From e99d690d2dedc44e53dbdb36c63bc605ebbb419d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20=C3=81ngel=20San=20Mart=C3=ADn?= Date: Mon, 21 Jan 2013 17:11:26 +0100 Subject: [PATCH] a?adido widget para la gesti?n de la informationLabel --- YACReader/YACReader.pro | 4 +- YACReader/images.qrc | 1 + YACReader/page_label_widget.cpp | 94 ++++++++++++++++++++++++++++++++ YACReader/page_label_widget.h | 29 ++++++++++ YACReader/viewer.cpp | 15 ++--- YACReader/viewer.h | 3 +- images/numPagesLabel.png | Bin 0 -> 585 bytes 7 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 YACReader/page_label_widget.cpp create mode 100644 YACReader/page_label_widget.h create mode 100644 images/numPagesLabel.png diff --git a/YACReader/YACReader.pro b/YACReader/YACReader.pro index fa4ec132..6feddf8c 100644 --- a/YACReader/YACReader.pro +++ b/YACReader/YACReader.pro @@ -45,13 +45,14 @@ HEADERS += comic.h \ translator.h \ goto_flow_gl.h \ goto_flow_widget.h \ + page_label_widget.h \ ../common/pictureflow.h \ ../common/custom_widgets.h \ ../common/check_new_version.h \ ../common/qnaturalsorting.h \ ../common/yacreader_flow_gl.h \ ../common/yacreader_global.h \ - ../common/onstart_flow_selection_dialog.h + ../common/onstart_flow_selection_dialog.h SOURCES += comic.cpp \ configuration.cpp \ @@ -69,6 +70,7 @@ SOURCES += comic.cpp \ translator.cpp \ goto_flow_gl.cpp \ goto_flow_widget.cpp \ + page_label_widget.cpp \ ../common/pictureflow.cpp \ ../common/custom_widgets.cpp \ ../common/check_new_version.cpp \ diff --git a/YACReader/images.qrc b/YACReader/images.qrc index f706cebb..317f771a 100644 --- a/YACReader/images.qrc +++ b/YACReader/images.qrc @@ -35,6 +35,7 @@ ../images/dictionary.png ../images/alwaysOnTop.png ../images/adjustToFullSize.png + ../images/numPagesLabel.png ../images/helpImages/open.png ../images/helpImages/openFolder.png ../images/helpImages/next.png diff --git a/YACReader/page_label_widget.cpp b/YACReader/page_label_widget.cpp new file mode 100644 index 00000000..5cc04bfd --- /dev/null +++ b/YACReader/page_label_widget.cpp @@ -0,0 +1,94 @@ +#include "page_label_widget.h" + +#include +#include +#include + +PageLabelWidget::PageLabelWidget(QWidget * parent) + :QWidget(parent) + { + animation = new QPropertyAnimation(this,"pos"); + animation->setDuration(150); + + + imgLabel = new QLabel(this); + QPixmap p(":/images/numPagesLabel.png"); + imgLabel->resize(p.size()); + imgLabel->setPixmap(QPixmap(":/images/numPagesLabel.png")); + + textLabel = new QLabel(this); + textLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter); + textLabel->setStyleSheet("QLabel { color : white; }"); + //informationLabel->setAutoFillBackground(true); + //textLabel->setFont(QFont("courier new bold", 12)); + //textLabel->resize(100,25); + + textLabel->setGeometry(imgLabel->geometry()); + + /*QSize size = textLabel->sizeHint(); + + int w = width(); // returns screen width + int h = height(); // returns screen height + int mw = size.width(); + int mh = size.height(); + int cw = (w-mw)/2; + int ch = 0; + textLabel->move(cw,ch);*/ + } + +void PageLabelWidget::show() +{ + if(this->pos().y() <= 0 && animation->state()!=QPropertyAnimation::Running) + { + QWidget * parent = dynamic_cast(this->parent()); + if(parent == 0) + { + return; + } + + QWidget::show(); + //connect(animation,SIGNAL(finished()),this,SLOT(QWidget::hide())); + animation->disconnect(); + + animation->setStartValue(QPoint((parent->geometry().size().width()-this->width())/2,-this->height())); + animation->setEndValue(QPoint((parent->geometry().size().width()-this->width())/2,0)); + animation->start(); + } +} + +void PageLabelWidget::hide() +{ + + if(this->pos().y() >= 0 && animation->state()!=QPropertyAnimation::Running) + { + QWidget * parent = dynamic_cast(this->parent()); + if(parent == 0) + { + return; + } + //connect(animation,SIGNAL(finished()),this,SLOT(setHidden())); + animation->setStartValue(QPoint((parent->geometry().size().width()-this->width())/2,0)); + animation->setEndValue(QPoint((parent->geometry().size().width()-this->width())/2,-this->height())); + animation->start(); + } +} + +void PageLabelWidget::setText(const QString & text) +{ + textLabel->setText(text); + QRect geom = imgLabel->geometry(); + QSize size = geom.size(); + size.setHeight(size.height() - 10); //TODO remove this amazing magic number + geom.setSize(size); + textLabel->setGeometry(geom); +} + +/*void PageLabelWidget::resizeEvent(QResizeEvent * event) +{ + move(QPoint((((QWidget *) parent())->geometry().size().width()-this->width())/2,0)); +}*/ + +void PageLabelWidget::updatePosition() +{ + move(QPoint((((QWidget *) parent())->geometry().size().width()-this->width())/2,this->pos().y())); +} \ No newline at end of file diff --git a/YACReader/page_label_widget.h b/YACReader/page_label_widget.h new file mode 100644 index 00000000..3d83b193 --- /dev/null +++ b/YACReader/page_label_widget.h @@ -0,0 +1,29 @@ +#ifndef PAGE_LABEL_WIDGET_H +#define PAGE_LABEL_WIDGET_H + +#include + +class QLabel; +class QPropertyAnimation; + +class PageLabelWidget : public QWidget +{ +Q_OBJECT +private: + QLabel * imgLabel; + QLabel * textLabel; + QPropertyAnimation * animation; + + //void resizeEvent(QResizeEvent * event); + +public: + PageLabelWidget(QWidget * parent); + +public slots: + void show(); + void hide(); + void setText(const QString & text); + void updatePosition(); +}; + +#endif \ No newline at end of file diff --git a/YACReader/viewer.cpp b/YACReader/viewer.cpp index ee28cf0d..34df22b9 100644 --- a/YACReader/viewer.cpp +++ b/YACReader/viewer.cpp @@ -9,6 +9,7 @@ #include "goto_dialog.h" #include "translator.h" #include "onstart_flow_selection_dialog.h" +#include "page_label_widget.h" #include #include @@ -56,12 +57,8 @@ drag(false) content->setMouseTracking(true); setMouseTracking(true); - informationLabel = new QLabel(this); - informationLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter); - informationLabel->setAutoFillBackground(true); - informationLabel->setFont(QFont("courier new", 12)); + informationLabel = new PageLabelWidget(this); informationLabel->hide(); - informationLabel->resize(100,25); showCursor(); @@ -160,6 +157,8 @@ void Viewer::open(QString pathFile) //render->update(); verticalScrollBar()->setSliderPosition(verticalScrollBar()->minimum()); + + informationLabel->setText("..."); } void Viewer::showMessageErrorOpening() @@ -171,12 +170,14 @@ void Viewer::next() { direction = 1; render->nextPage(); + updateInformation(); } void Viewer::prev() { direction = -1; render->previousPage(); + updateInformation(); } void Viewer::showGoToDialog() { @@ -407,7 +408,7 @@ void Viewer::resizeEvent(QResizeEvent * event) { updateContentSize(); goToFlow->move(QPoint((width()-goToFlow->width())/2,height()-goToFlow->height())); - informationLabel->move(QPoint((width()-informationLabel->width())/2,0)); + informationLabel->updatePosition(); QScrollArea::resizeEvent(event); } @@ -487,7 +488,7 @@ void Viewer::hideMagnifyingGlass() void Viewer::informationSwitch() { information?informationLabel->hide():informationLabel->show(); - informationLabel->move(QPoint((width()-informationLabel->width())/2,0)); + //informationLabel->move(QPoint((width()-informationLabel->width())/2,0)); information=!information; //TODO it shouldn't be neccesary informationLabel->adjustSize(); diff --git a/YACReader/viewer.h b/YACReader/viewer.h index 72dc508a..91d30203 100644 --- a/YACReader/viewer.h +++ b/YACReader/viewer.h @@ -26,6 +26,7 @@ class GoToDialog; class YACReaderTranslator; class GoToFlowWidget; class Bookmarks; +class PageLabelWidget; class Viewer : public QScrollArea { @@ -80,7 +81,7 @@ virtual void mouseReleaseEvent ( QMouseEvent * event ); private: bool information; bool doublePage; - QLabel * informationLabel; + PageLabelWidget * informationLabel; //QTimer * scroller; QPropertyAnimation * verticalScroller; int posByStep; diff --git a/images/numPagesLabel.png b/images/numPagesLabel.png new file mode 100644 index 0000000000000000000000000000000000000000..54ca6241d7834578c356f4a27700b55cc67a8aad GIT binary patch literal 585 zcmV-P0=E5$P)q$gGRCwC#n@vi?Kpe#IJsn_e7!C-KS%X|0{euHB;Z?C&4O;eL)8CS1?lD%K2N?`Il z=jsud&4FRU5Ev#5#e|`lFcg8IcqCB-#wtk?CJcdL!cad;!h#)!V(F#+S%=|~L|~XO z)ZcX&CJYmX2}7~NP)rzV*E$Rnh6%%jp*B(&hT8)Z$MMATypt%3xPlE*r_+(3m}~=# z#7ge_{&lz8y~3{{G|hnpdv0X!EeBP=*a=cx(jW*%IF?SK3)giIcj=Eij>FymUD=&s z-*3m`@kkg@78bxM10xfpBEQ3P+;|5+;QAQegIz9bJ$o+v0l&h5?7cFO6rfoNjNB+6 zEY09&*d|M;z_hrwwN$3S$Omgry7x0>A*}*Nh?2rGg?$~D8xIIfBY>GJEWR=jDHBV; z6ptgB^rGW)O_}||To#0S$-ZQufDoW1eF`uD X9s^Ojg$QI{00000NkvXXu0mjf#<2gb literal 0 HcmV?d00001