diff --git a/YACReader/YACReader.pro b/YACReader/YACReader.pro index 6feddf8c..25fe7d8d 100644 --- a/YACReader/YACReader.pro +++ b/YACReader/YACReader.pro @@ -46,6 +46,8 @@ HEADERS += comic.h \ goto_flow_gl.h \ goto_flow_widget.h \ page_label_widget.h \ + goto_flow_toolbar.h \ + goto_flow_decorationbar.h \ ../common/pictureflow.h \ ../common/custom_widgets.h \ ../common/check_new_version.h \ @@ -71,6 +73,8 @@ SOURCES += comic.cpp \ goto_flow_gl.cpp \ goto_flow_widget.cpp \ page_label_widget.cpp \ + goto_flow_toolbar.cpp \ + goto_flow_decorationbar.cpp \ ../common/pictureflow.cpp \ ../common/custom_widgets.cpp \ ../common/check_new_version.cpp \ diff --git a/YACReader/goto_dialog.cpp b/YACReader/goto_dialog.cpp index 8b8dd66d..4b865d07 100644 --- a/YACReader/goto_dialog.cpp +++ b/YACReader/goto_dialog.cpp @@ -62,7 +62,7 @@ void GoToDialog::goTo() pageNumber->clear(); if(page >= 1) - emit(goToPage(page)); + emit(goToPage(page-1)); close(); diff --git a/YACReader/goto_flow.cpp b/YACReader/goto_flow.cpp index ae1765e0..24c7513d 100644 --- a/YACReader/goto_flow.cpp +++ b/YACReader/goto_flow.cpp @@ -11,6 +11,9 @@ #include #include +#include "goto_flow_toolbar.h" +#include "goto_flow_decorationbar.h" + /*#define WIDTH 126 #define HEIGHT 200*/ @@ -26,87 +29,36 @@ GoToFlow::GoToFlow(QWidget *parent,FlowType flowType) worker = new PageLoader; - QVBoxLayout * layout = new QVBoxLayout(this); + flow = new YACReaderFlow(this,flowType); flow->setReflectionEffect(PictureFlow::PlainReflection); imageSize = Configuration::getConfiguration().getGotoSlideSize(); flow->setSlideSize(imageSize); connect(flow,SIGNAL(centerIndexChanged(int)),this,SLOT(setPageNumber(int))); - connect(flow,SIGNAL(selected(unsigned int)),this,SLOT(goTo())); + connect(flow,SIGNAL(selected(unsigned int)),this,SIGNAL(goToPage(unsigned int))); - QHBoxLayout * bottom = new QHBoxLayout(this); - bottom->addStretch(); - bottom->addWidget(new QLabel(tr("Page : "),this)); - bottom->addWidget(edit = new QLineEdit(this)); - v = new QIntValidator(this); - v->setBottom(1); - edit->setValidator(v); - edit->setAlignment(Qt::AlignRight|Qt::AlignVCenter); - edit->setFixedWidth(40); - edit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum)); + connect(toolBar,SIGNAL(goTo(unsigned int)),this,SIGNAL(goToPage(unsigned int))); + connect(toolBar,SIGNAL(setCenter(unsigned int)),flow,SLOT(showSlide(unsigned int))); - centerButton = new QPushButton(this); - centerButton->setIcon(QIcon(":/images/center.png")); - connect(centerButton,SIGNAL(clicked()),this,SLOT(centerSlide())); - bottom->addWidget(centerButton); + mainLayout->insertWidget(1,flow); + mainLayout->setStretchFactor(flow,1); - goToButton = new QPushButton(this); - goToButton->setIcon(QIcon(":/images/goto.png")); - connect(goToButton,SIGNAL(clicked()),this,SLOT(goTo())); - bottom->addWidget(goToButton); - - bottom->addStretch(); - - layout->addWidget(flow); - layout->addLayout(bottom); - layout->setStretchFactor(flow,1); - layout->setStretchFactor(bottom,0); - layout->setMargin(0); - layout->setSpacing(0); - setLayout(layout); - this->setAutoFillBackground(true); resize(static_cast(5*imageSize.width()),static_cast(imageSize.height()*1.7)); //install eventFilter //flow->installEventFilter(this); - edit->installEventFilter(this); + /*edit->installEventFilter(this); centerButton->installEventFilter(this); goToButton->installEventFilter(this); - connect(edit,SIGNAL(returnPressed()),goToButton,SIGNAL(clicked())); + connect(edit,SIGNAL(returnPressed()),goToButton,SIGNAL(clicked()));*/ this->setCursor(QCursor(Qt::ArrowCursor)); } -void GoToFlow::goTo() -{ - //emit(goToPage(flow->centerIndex()+1)); - emit(goToPage(edit->text().toInt())); -} - -void GoToFlow::setPageNumber(int page) -{ - edit->setText(QString::number(page+1)); -} - -void GoToFlow::centerSlide() -{ - int page = edit->text().toInt()-1; - int distance = flow->centerIndex()-page; - - if(abs(distance)>10) - { - if(distance<0) - flow->setCenterIndex(flow->centerIndex()+(-distance)-10); - else - flow->setCenterIndex(flow->centerIndex()-distance+10); - } - - flow->showSlide(page); -} void GoToFlow::centerSlide(int slide) { @@ -131,7 +83,7 @@ void GoToFlow::setNumSlides(unsigned int slides) rawImages.clear(); rawImages.resize(slides); - v->setTop(slides); + toolBar->setTop(slides); SlideInitializer * si = new SlideInitializer(flow,slides); @@ -241,28 +193,6 @@ bool GoToFlow::eventFilter(QObject *target, QEvent *event) return QWidget::eventFilter(target, event); } - -void GoToFlow::keyPressEvent(QKeyEvent* event) -{ - switch (event->key()) - { - case Qt::Key_Return: case Qt::Key_Enter: - goTo(); - centerSlide(); - break; - case Qt::Key_Space: - centerSlide(); - break; - case Qt::Key_S: - QCoreApplication::sendEvent(this->parent(),event); - break; - case Qt::Key_Left: case Qt::Key_Right: - QCoreApplication::sendEvent(flow,event); - } - - event->accept(); -} - void GoToFlow::wheelEvent(QWheelEvent * event) { if(event->delta()<0) diff --git a/YACReader/goto_flow.h b/YACReader/goto_flow.h index f194cc69..0b48b824 100644 --- a/YACReader/goto_flow.h +++ b/YACReader/goto_flow.h @@ -24,14 +24,9 @@ class GoToFlow : public GoToFlowWidget public: GoToFlow(QWidget* parent = 0,FlowType flowType = CoverFlowLike); bool ready; //comic is ready for read. - void keyPressEvent(QKeyEvent* event); bool eventFilter(QObject *target, QEvent *event); private: YACReaderFlow * flow; - QLineEdit * edit; - QIntValidator * v; - QPushButton * centerButton; - QPushButton * goToButton; //Comic * comic; QSize imageSize; @@ -49,9 +44,6 @@ private: void updateImageData(); public slots: - void goTo(); - void setPageNumber(int page); - void centerSlide(); void centerSlide(int slide); void reset(); void setNumSlides(unsigned int slides); diff --git a/YACReader/goto_flow_decorationbar.cpp b/YACReader/goto_flow_decorationbar.cpp new file mode 100644 index 00000000..c9ef2fbb --- /dev/null +++ b/YACReader/goto_flow_decorationbar.cpp @@ -0,0 +1,33 @@ +#include "goto_flow_decorationbar.h" + +#include +#include + +GoToFlowDecorationBar::GoToFlowDecorationBar(QWidget * parent) +:QWidget(parent) +{ + QHBoxLayout * topBar = new QHBoxLayout(); + + QLabel * imgTopLeft = new QLabel(); + QLabel * imgTopRight = new QLabel(); + QLabel * imgTopMiddle = new QLabel(); + QPixmap pL(":/images/imgTopLeft.png"); + QPixmap pM(":/images/imgTopMiddle.png"); + QPixmap pR(":/images/imgTopRight.png"); + imgTopLeft->setPixmap(pL); + imgTopRight->setPixmap(pR); + imgTopMiddle->setPixmap(pM); + imgTopMiddle->setScaledContents(true); + + topBar->addWidget(imgTopLeft); + topBar->addWidget(imgTopMiddle); + topBar->addWidget(imgTopRight); + topBar->setStretchFactor(imgTopLeft,0); + topBar->setStretchFactor(imgTopMiddle,1); + topBar->setStretchFactor(imgTopRight,0); + + topBar->setMargin(0); + topBar->setSpacing(0); + + setLayout(topBar); +} \ No newline at end of file diff --git a/YACReader/goto_flow_decorationbar.h b/YACReader/goto_flow_decorationbar.h new file mode 100644 index 00000000..10397124 --- /dev/null +++ b/YACReader/goto_flow_decorationbar.h @@ -0,0 +1,13 @@ +#ifndef GOTO_FLOW_DECORATIONBAR_H +#define GOTO_FLOW_DECORATIONBAR_H + +#include + +class GoToFlowDecorationBar : public QWidget +{ + Q_OBJECT + public: + GoToFlowDecorationBar(QWidget * parent = 0); +}; + +#endif \ No newline at end of file diff --git a/YACReader/goto_flow_gl.cpp b/YACReader/goto_flow_gl.cpp index 0a9ace11..a4fe1d1d 100644 --- a/YACReader/goto_flow_gl.cpp +++ b/YACReader/goto_flow_gl.cpp @@ -8,135 +8,34 @@ #include "configuration.h" +#include "goto_flow_toolbar.h" +#include "goto_flow_decorationbar.h" + GoToFlowGL::GoToFlowGL(QWidget* parent, FlowType flowType) :GoToFlowWidget(parent) { - //worker = new PageLoader; - QVBoxLayout * layout = new QVBoxLayout(this); flow = new YACReaderPageFlowGL(this); - //flow->populate(50); - //flow->setReflectionEffect(PictureFlow::PlainReflection); + imageSize = Configuration::getConfiguration().getGotoSlideSize(); flow->setSlideSize(imageSize); connect(flow,SIGNAL(centerIndexChanged(int)),this,SLOT(setPageNumber(int))); - connect(flow,SIGNAL(selected(unsigned int)),this,SLOT(goTo())); + connect(flow,SIGNAL(selected(unsigned int)),this,SIGNAL(goToPage(unsigned int))); - QHBoxLayout * topBar = new QHBoxLayout(); + connect(toolBar,SIGNAL(goTo(unsigned int)),this,SIGNAL(goToPage(unsigned int))); + connect(toolBar,SIGNAL(setCenter(unsigned int)),flow,SLOT(setCenterIndex(unsigned int))); - QLabel * imgTopLeft = new QLabel(); - QLabel * imgTopRight = new QLabel(); - QLabel * imgTopMiddle = new QLabel(); - QPixmap pL(":/images/imgTopLeft.png"); - QPixmap pM(":/images/imgTopMiddle.png"); - QPixmap pR(":/images/imgTopRight.png"); - imgTopLeft->setPixmap(pL); - imgTopRight->setPixmap(pR); - imgTopMiddle->setPixmap(pM); - imgTopMiddle->setScaledContents(true); - //imgTop->setStyleSheet("background-image: url(:/images/numPagesLabel.png); width: 100%; height:100%; background-repeat: none; border: none"); + mainLayout->insertWidget(1,flow); + mainLayout->setStretchFactor(flow,1); - topBar->addWidget(imgTopLeft); - topBar->addWidget(imgTopMiddle); - topBar->addWidget(imgTopRight); - topBar->setStretchFactor(imgTopLeft,0); - topBar->setStretchFactor(imgTopMiddle,1); - topBar->setStretchFactor(imgTopRight,0); - - QHBoxLayout * bottomBar = new QHBoxLayout(this); - - QLabel * imgBottomLeft = new QLabel(this); - QLabel * imgBottomRight = new QLabel(this); - QLabel * imgBottomMiddle = new QLabel(this); - QPixmap pBL(":/images/imgBottomLeft.png"); - QPixmap pBM(":/images/imgBottomMiddle.png"); - QPixmap pBR(":/images/imgBottomRight.png"); - imgBottomLeft->setPixmap(pBL); - imgBottomRight->setPixmap(pBR); - imgBottomMiddle->setPixmap(pBM); - imgBottomMiddle->setScaledContents(true); - //imgTop->setStyleSheet("background-image: url(:/images/numPagesLabel.png); width: 100%; height:100%; background-repeat: none; border: none"); - - bottomBar->addWidget(imgBottomLeft); - bottomBar->addWidget(imgBottomMiddle); - bottomBar->addWidget(imgBottomRight); - bottomBar->setStretchFactor(imgBottomLeft,0); - bottomBar->setStretchFactor(imgBottomMiddle,1); - bottomBar->setStretchFactor(imgBottomRight,0); - - bottomToolBar = new QWidget(this); - - QHBoxLayout * bottom = new QHBoxLayout(bottomToolBar); - bottom->addStretch(); - bottom->addWidget(new QLabel(tr("Page : "),bottomToolBar)); - bottom->addWidget(edit = new QLineEdit(bottomToolBar)); - v = new QIntValidator(this); - v->setBottom(1); - edit->setValidator(v); - edit->setAlignment(Qt::AlignRight|Qt::AlignVCenter); - edit->setStyleSheet("background-image: url(:/images/imgEdit.png); width: 100%; height:100%; background-repeat: none; border: none; padding: 3px; color: white;"); - QPixmap p(":/images/imgEdit.png"); - edit->setFixedSize(54,50); - //edit->resize(QSize(54,50)); - edit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed)); - edit->setAutoFillBackground(false); - - QString centerButtonCSS = "QPushButton {background-image: url(:/images/imgCenterSlide.png); width: 100%; height:100%; background-repeat: none; border: none;} " - "QPushButton:focus { border: none; outline: none;}" - "QPushButton:pressed {background-image: url(:/images/imgCenterSlidePressed.png); width: 100%; height:100%; background-repeat: none; border: none;} "; - centerButton = new QPushButton(bottomToolBar); - //centerButton->setIcon(QIcon(":/images/center.png")); - centerButton->setStyleSheet(centerButtonCSS); - centerButton->setFixedSize(26,50); - connect(centerButton,SIGNAL(clicked()),this,SLOT(centerSlide())); - bottom->addWidget(centerButton); - - QString goToButtonCSS = "QPushButton {background-image: url(:/images/imgGoToSlide.png); width: 100%; height:100%; background-repeat: none; border: none;} " - "QPushButton:focus { border: none; outline: none;}" - "QPushButton:pressed {background-image: url(:/images/imgGoToSlidePressed.png); width: 100%; height:100%; background-repeat: none; border: none;} "; - goToButton = new QPushButton(bottomToolBar); - //goToButton->setIcon(QIcon(":/images/goto.png")); - goToButton->setStyleSheet(goToButtonCSS); - goToButton->setFixedSize(32,50); - connect(goToButton,SIGNAL(clicked()),this,SLOT(goTo())); - bottom->addWidget(goToButton); - - bottom->addStretch(); - bottom->setMargin(0); - bottom->setSpacing(0); - - - /* QGraphicsDropShadowEffect* effect = new QGraphicsDropShadowEffect( this ); - effect->setBlurRadius(100); - effect->setOffset(0,3); - effect->setColor(Qt::black); - setGraphicsEffect( effect );*/ - - - layout->addLayout(topBar); - layout->addWidget(flow); - //layout->addLayout(bottom); - layout->addLayout(bottomBar); - layout->setStretchFactor(flow,1); - layout->setStretchFactor(bottomBar,0); - layout->setMargin(0); - layout->setSpacing(0); - setLayout(layout); - //this->setAutoFillBackground(true); resize(static_cast(5*imageSize.width()),static_cast(imageSize.height()*1.7)); - //bottomToolBar->setAutoFillBackground(true); - bottomToolBar->setLayout(bottom); - bottomToolBar->setGeometry(QRect(0,0,400,50)); - //install eventFilter - flow->installEventFilter(this); - edit->installEventFilter(this); - centerButton->installEventFilter(this); - goToButton->installEventFilter(this); - - connect(edit,SIGNAL(returnPressed()),goToButton,SIGNAL(clicked())); + //flow->installEventFilter(this); + //edit->installEventFilter(this); + //centerButton->installEventFilter(this); + //goToButton->installEventFilter(this); this->setCursor(QCursor(Qt::ArrowCursor)); } @@ -158,46 +57,13 @@ bool GoToFlowGL::eventFilter(QObject *target, QEvent *event) return QWidget::eventFilter(target, event); } -void GoToFlowGL::keyPressEvent(QKeyEvent* event) -{ - switch (event->key()) - { - case Qt::Key_Return: case Qt::Key_Enter: - goTo(); - centerSlide(); - break; - case Qt::Key_Space: - centerSlide(); - break; - case Qt::Key_S: - QCoreApplication::sendEvent(this->parent(),event); - break; - case Qt::Key_Left: case Qt::Key_Right: - //if(event->modifiers() == Qt::ControlModifier) - //flow->keyPressEvent(event); - //QCoreApplication::sendEvent(flow,event); - break; - } - event->accept(); -} - -void GoToFlowGL::goTo() -{ - emit(goToPage(edit->text().toInt())); -} void GoToFlowGL::reset() { flow->reset(); } -void GoToFlowGL::centerSlide() -{ - int page = edit->text().toInt()-1; - flow->setCenterIndex(page); -} - void GoToFlowGL::centerSlide(int slide) { if(flow->centerIndex()!=slide) @@ -205,10 +71,6 @@ void GoToFlowGL::centerSlide(int slide) flow->setCenterIndex(slide); } } -void GoToFlowGL::setPageNumber(int page) -{ - edit->setText(QString::number(page+1)); -} void GoToFlowGL::setFlowType(FlowType flowType) { @@ -225,20 +87,14 @@ void GoToFlowGL::setFlowType(FlowType flowType) void GoToFlowGL::setNumSlides(unsigned int slides) { flow->populate(slides); - v->setTop(slides); + toolBar->setTop(slides); } void GoToFlowGL::setImageReady(int index,const QByteArray & imageData) { flow->rawImages[index] = imageData; flow->imagesReady[index] = true; - - //QImage image; - //image.loadFromData(imageData); - //float x = 1; - //float y = 1 * (float(image.height())/image.width()); - //image = image.scaledToWidth(128,Qt::SmoothTransformation); - //flow->replace("cover",flow->bindTexture(image,GL_TEXTURE_2D,GL_RGB,QGLContext::LinearFilteringBindOption | QGLContext::MipmapBindOption),x,y,index); } + void GoToFlowGL::updateSize() { @@ -305,10 +161,3 @@ void GoToFlowGL::updateConfig(QSettings * settings) } -void GoToFlowGL::resizeEvent(QResizeEvent * event) -{ - - bottomToolBar->setGeometry(QRect(0,(event->size().height()-50)+((50-bottomToolBar->height())/2),event->size().width(),50)); - - GoToFlowWidget::resizeEvent(event); -} \ No newline at end of file diff --git a/YACReader/goto_flow_gl.h b/YACReader/goto_flow_gl.h index c8c4ad99..9318e525 100644 --- a/YACReader/goto_flow_gl.h +++ b/YACReader/goto_flow_gl.h @@ -17,16 +17,13 @@ class GoToFlowGL : public GoToFlowWidget public: GoToFlowGL(QWidget* parent = 0,FlowType flowType = CoverFlowLike); void reset(); - void centerSlide(); void centerSlide(int slide); - void setPageNumber(int page); void setFlowType(FlowType flowType); void setNumSlides(unsigned int slides); void setImageReady(int index,const QByteArray & image); void updateSize(); - void goTo(); bool eventFilter(QObject *target, QEvent *event); - void keyPressEvent(QKeyEvent* event); + void updateConfig(QSettings * settings); signals: @@ -34,15 +31,9 @@ signals: private: YACReaderPageFlowGL * flow; - QLineEdit * edit; - QIntValidator * v; - QPushButton * centerButton; - QPushButton * goToButton; + //Comic * comic; QSize imageSize; - QWidget * bottomToolBar; - void resizeEvent(QResizeEvent * event); - }; #endif \ No newline at end of file diff --git a/YACReader/goto_flow_toolbar.cpp b/YACReader/goto_flow_toolbar.cpp new file mode 100644 index 00000000..5c16ba00 --- /dev/null +++ b/YACReader/goto_flow_toolbar.cpp @@ -0,0 +1,115 @@ +#include "goto_flow_toolbar.h" + +#include +#include +#include +#include +#include +#include +#include + +GoToFlowToolBar::GoToFlowToolBar(QWidget * parent) + :QWidget(parent) +{ + //fondo + QBoxLayout * background = new QHBoxLayout(this); + + QLabel * imgBottomLeft = new QLabel(this); + QLabel * imgBottomRight = new QLabel(this); + QLabel * imgBottomMiddle = new QLabel(this); + QPixmap pBL(":/images/imgBottomLeft.png"); + QPixmap pBM(":/images/imgBottomMiddle.png"); + QPixmap pBR(":/images/imgBottomRight.png"); + imgBottomLeft->setPixmap(pBL); + imgBottomRight->setPixmap(pBR); + imgBottomMiddle->setPixmap(pBM); + imgBottomMiddle->setScaledContents(true); + //imgTop->setStyleSheet("background-image: url(:/images/numPagesLabel.png); width: 100%; height:100%; background-repeat: none; border: none"); + + background->addWidget(imgBottomLeft); + background->addWidget(imgBottomMiddle); + background->addWidget(imgBottomRight); + background->setStretchFactor(imgBottomLeft,0); + background->setStretchFactor(imgBottomMiddle,1); + background->setStretchFactor(imgBottomRight,0); + + background->setMargin(0); + background->setSpacing(0); + + //elementos interactivos + //QVBoxLayout * mainLayout = new QVBoxLayout; + bar = new QWidget(this); + QHBoxLayout * bottom = new QHBoxLayout(bar); + bottom->addStretch(); + bottom->addWidget(new QLabel(tr("Page : "),bar)); + bottom->addWidget(edit = new QLineEdit(bar)); + v = new QIntValidator(bar); + v->setBottom(1); + edit->setValidator(v); + edit->setAlignment(Qt::AlignRight|Qt::AlignVCenter); + edit->setStyleSheet("background-image: url(:/images/imgEdit.png); width: 100%; height:100%; background-repeat: none; border: none; padding: 3px; color: white;"); + QPixmap p(":/images/imgEdit.png"); + edit->setFixedSize(54,50); + //edit->resize(QSize(54,50)); + edit->setSizePolicy(QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed)); + edit->setAutoFillBackground(false); + connect(edit,SIGNAL(returnPressed()),this,SLOT(goTo())); + + QString centerButtonCSS = "QPushButton {background-image: url(:/images/imgCenterSlide.png); width: 100%; height:100%; background-repeat: none; border: none;} " + "QPushButton:focus { border: none; outline: none;}" + "QPushButton:pressed {background-image: url(:/images/imgCenterSlidePressed.png); width: 100%; height:100%; background-repeat: none; border: none;} "; + centerButton = new QPushButton(bar); + //centerButton->setIcon(QIcon(":/images/center.png")); + centerButton->setStyleSheet(centerButtonCSS); + centerButton->setFixedSize(26,50); + connect(centerButton,SIGNAL(clicked()),this,SLOT(centerSlide())); + bottom->addWidget(centerButton); + + QString goToButtonCSS = "QPushButton {background-image: url(:/images/imgGoToSlide.png); width: 100%; height:100%; background-repeat: none; border: none;} " + "QPushButton:focus { border: none; outline: none;}" + "QPushButton:pressed {background-image: url(:/images/imgGoToSlidePressed.png); width: 100%; height:100%; background-repeat: none; border: none;} "; + goToButton = new QPushButton(bar); + //goToButton->setIcon(QIcon(":/images/goto.png")); + goToButton->setStyleSheet(goToButtonCSS); + goToButton->setFixedSize(32,50); + connect(goToButton,SIGNAL(clicked()),this,SLOT(goTo())); + bottom->addWidget(goToButton); + + bottom->addStretch(); + bottom->setMargin(0); + bottom->setSpacing(0); + + bar->setLayout(bottom); + //mainLayout->addWidget(bar); + setLayout(background); + bar->setGeometry(QRect(0,0,400,50)); + +} + +void GoToFlowToolBar::setPage(int pageNumber) +{ + edit->setText(QString::number(pageNumber+1)); +} + +void GoToFlowToolBar::setTop(int numPages) +{ + v->setTop(numPages); +} + +void GoToFlowToolBar::resizeEvent(QResizeEvent * event) +{ + + bar->setGeometry(QRect(0,(event->size().height()-50)+((50-bar->height())/2),event->size().width(),50)); + + QWidget::resizeEvent(event); +} + +void GoToFlowToolBar::goTo() +{ + emit(goTo(edit->text().toInt()-1)); +} + +void GoToFlowToolBar::centerSlide() +{ + emit(setCenter(edit->text().toInt()-1)); +} \ No newline at end of file diff --git a/YACReader/goto_flow_toolbar.h b/YACReader/goto_flow_toolbar.h new file mode 100644 index 00000000..0fe6694d --- /dev/null +++ b/YACReader/goto_flow_toolbar.h @@ -0,0 +1,33 @@ +#ifndef GOTO_FLOW_TOOLBAR_H +#define GOTO_FLOW_TOOLBAR_H + +#include + +class QLineEdit; +class QIntValidator; +class QPushButton; + +class GoToFlowToolBar : public QWidget +{ + Q_OBJECT + private: + QLineEdit * edit; + QIntValidator * v; + QPushButton * centerButton; + QPushButton * goToButton; + QWidget * bar; + void resizeEvent(QResizeEvent * event); + + public: + GoToFlowToolBar(QWidget * parent = 0); + public slots: + void setPage(int pageNumber); + void setTop(int numPages); + void goTo(); + void centerSlide(); + signals: + void setCenter(unsigned int); + void goTo(unsigned int); +}; + +#endif \ No newline at end of file diff --git a/YACReader/goto_flow_widget.cpp b/YACReader/goto_flow_widget.cpp index 30d9070f..837a9cfa 100644 --- a/YACReader/goto_flow_widget.cpp +++ b/YACReader/goto_flow_widget.cpp @@ -1,9 +1,58 @@ #include "goto_flow_widget.h" +#include +#include +#include +#include + +#include "goto_flow_toolbar.h" +#include "goto_flow_decorationbar.h" + GoToFlowWidget::GoToFlowWidget(QWidget * parent) :QWidget(parent) { - QPalette palette; - palette.setColor(backgroundRole(), Qt::black); - setPalette(palette); + mainLayout = new QVBoxLayout; + + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + topBar = new GoToFlowDecorationBar(this); + toolBar = new GoToFlowToolBar(this); + + mainLayout->addWidget(topBar); + mainLayout->addWidget(toolBar); + + mainLayout->setMargin(0); + mainLayout->setSpacing(0); + + setLayout(mainLayout); +} + +void GoToFlowWidget::setPageNumber(int page) +{ + toolBar->setPage(page); +} + +void GoToFlowWidget::keyPressEvent(QKeyEvent* event) +{ + switch (event->key()) + { + case Qt::Key_Return: case Qt::Key_Enter: + toolBar->goTo(); + toolBar->centerSlide(); + break; + case Qt::Key_Space: + toolBar->centerSlide(); + break; + case Qt::Key_S: + QCoreApplication::sendEvent(this->parent(),event); + break; + case Qt::Key_Left: case Qt::Key_Right: + //if(event->modifiers() == Qt::ControlModifier) + //flow->keyPressEvent(event); + //QCoreApplication::sendEvent(flow,event); + break; + } + + event->accept(); } diff --git a/YACReader/goto_flow_widget.h b/YACReader/goto_flow_widget.h index 570adb0f..ce26fbb4 100644 --- a/YACReader/goto_flow_widget.h +++ b/YACReader/goto_flow_widget.h @@ -5,23 +5,33 @@ #include #include "yacreader_global.h" +class QSettings; +class GoToFlowDecorationBar; +class GoToFlowToolBar; +class QVBoxLayout; + class GoToFlowWidget : public QWidget { Q_OBJECT +protected: + QVBoxLayout * mainLayout; + GoToFlowDecorationBar * topBar; + GoToFlowToolBar * toolBar; public: GoToFlowWidget(QWidget * paret = 0); public slots: virtual void reset() = 0; - virtual void centerSlide() = 0; virtual void centerSlide(int slide) = 0; - virtual void setPageNumber(int page) = 0; + virtual void setPageNumber(int page); virtual void setFlowType(FlowType flowType) = 0; virtual void setNumSlides(unsigned int slides) = 0; virtual void setImageReady(int index,const QByteArray & image) = 0; virtual void updateSize() = 0; - virtual void goTo() = 0; virtual void updateConfig(QSettings * settings) = 0; +protected: + void keyPressEvent(QKeyEvent* event); + }; #endif diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index 2cd10b8a..d55e5a32 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -186,7 +186,7 @@ void Viewer::showGoToDialog() void Viewer::goTo(unsigned int page) { direction = 1; //in "go to" direction is always fordward - render->goTo(page-1); + render->goTo(page); } void Viewer::updatePage() diff --git a/common/pictureflow.cpp b/common/pictureflow.cpp index 5f308b84..a03c0b54 100644 --- a/common/pictureflow.cpp +++ b/common/pictureflow.cpp @@ -1178,13 +1178,23 @@ void PictureFlow::showNext() d->animator->target = qMin(center + 2, slideCount()-1); } -void PictureFlow::showSlide(int index) +void PictureFlow::showSlide(unsigned int index) { - index = qMax(index, 0); - index = qMin(slideCount()-1, index); + index = qMax(index, 0); + index = qMin(slideCount()-1, index); if(index == d->state->centerSlide.slideIndex) return; + int distance = centerIndex()-index; + + if(abs(distance)>10) + { + if(distance<0) + setCenterIndex(centerIndex()+(-distance)-10); + else + setCenterIndex(centerIndex()-distance+10); + } + d->animator->start(index); } diff --git a/common/pictureflow.h b/common/pictureflow.h index 3510b6e3..709d1ab9 100644 --- a/common/pictureflow.h +++ b/common/pictureflow.h @@ -166,7 +166,7 @@ public slots: /*! Go to specified slide using animation effect. */ - void showSlide(int index); + void showSlide(unsigned int index); /*! Rerender the widget. Normally this function will be automatically invoked diff --git a/common/yacreader_flow_gl.cpp b/common/yacreader_flow_gl.cpp index 1f590c14..301fc089 100644 --- a/common/yacreader_flow_gl.cpp +++ b/common/yacreader_flow_gl.cpp @@ -884,7 +884,7 @@ void YACReaderFlowGL::clear() reset(); } -void YACReaderFlowGL::setCenterIndex(int index) +void YACReaderFlowGL::setCenterIndex(unsigned int index) { setCurrentIndex(index); } diff --git a/common/yacreader_flow_gl.h b/common/yacreader_flow_gl.h index ea02f398..660361c2 100644 --- a/common/yacreader_flow_gl.h +++ b/common/yacreader_flow_gl.h @@ -253,7 +253,7 @@ public: void unmarkSlide(int index); void setSlideSize(QSize size); void clear(); - void setCenterIndex(int index); + void setCenterIndex(unsigned int index); void showSlide(int index); int centerIndex(); void updateMarks();