updated page information widget visual style

This commit is contained in:
Luis Ángel San Martín 2015-12-10 19:29:12 +01:00
parent 5dea77bb54
commit c015558223
2 changed files with 42 additions and 59 deletions

View File

@ -1,30 +1,27 @@
#include "page_label_widget.h" #include "page_label_widget.h"
#include <QLabel> #include <QtWidgets>
#include <QHBoxLayout>
#include <QPropertyAnimation>
#include <QApplication>
#include <QDesktopWidget>
PageLabelWidget::PageLabelWidget(QWidget * parent) PageLabelWidget::PageLabelWidget(QWidget * parent)
:QWidget(parent) :QWidget(parent)
{ {
animation = new QPropertyAnimation(this,"pos"); animation = new QPropertyAnimation(this,"pos");
animation->setDuration(150); animation->setDuration(150);
animation->setEndValue(QPoint((parent->geometry().size().width()-this->width()),-this->height())); animation->setEndValue(QPoint((parent->geometry().size().width()-this->width()),-this->height()));
int verticalRes = QApplication::desktop()->screenGeometry().height(); int verticalRes = QApplication::desktop()->screenGeometry().height();
imgLabel = new QLabel(this); QHBoxLayout *layout = new QHBoxLayout;
QPixmap p; layout->setMargin(0);
setContentsMargins(0,0,0,0);
QSize labelSize;
if (verticalRes <= 1024) if (verticalRes <= 1024)
p.load(":/images/numPagesLabel.png"); labelSize = QSize(135, 30);
else if (verticalRes <= 1200) else if (verticalRes <= 1200)
p.load(":/images/numPagesLabelMedium.png"); labelSize = QSize(170, 35);
else else
p.load(":/images/numPagesLabelBig.png"); labelSize = QSize(205, 45);
imgLabel->resize(p.size());
imgLabel->setPixmap(p);
textLabel = new QLabel(this); textLabel = new QLabel(this);
textLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter); textLabel->setAlignment(Qt::AlignVCenter|Qt::AlignHCenter);
@ -35,24 +32,14 @@ PageLabelWidget::PageLabelWidget(QWidget * parent)
else else
textLabel->setStyleSheet("QLabel { color : white; font-size:20px; padding-left:8px; }"); textLabel->setStyleSheet("QLabel { color : white; font-size:20px; padding-left:8px; }");
//informationLabel->setAutoFillBackground(true); setFixedSize(labelSize);
//textLabel->setFont(QFont("courier new bold", 12));
//textLabel->resize(100,25);
resize(p.size());
//por defecto aparece oculto
if(parent != 0) if(parent != 0)
move(QPoint((parent->geometry().size().width()-this->width()),-this->height())); move(QPoint((parent->geometry().size().width()-this->width()),-this->height()));
/*QSize size = textLabel->sizeHint();
int w = width(); // returns screen width layout->addWidget(textLabel);
int h = height(); // returns screen height setLayout(layout);
int mw = size.width(); }
int mh = size.height();
int cw = (w-mw)/2;
int ch = 0;
textLabel->move(cw,ch);*/
}
void PageLabelWidget::show() void PageLabelWidget::show()
{ {
@ -76,7 +63,6 @@ void PageLabelWidget::show()
void PageLabelWidget::hide() void PageLabelWidget::hide()
{ {
if(this->pos().y() >= 0 && animation->state()!=QPropertyAnimation::Running) if(this->pos().y() >= 0 && animation->state()!=QPropertyAnimation::Running)
{ {
QWidget * parent = dynamic_cast<QWidget *>(this->parent()); QWidget * parent = dynamic_cast<QWidget *>(this->parent());
@ -94,17 +80,14 @@ void PageLabelWidget::hide()
void PageLabelWidget::setText(const QString & text) void PageLabelWidget::setText(const QString & text)
{ {
textLabel->setText(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) void PageLabelWidget::paintEvent(QPaintEvent *)
{ {
move(QPoint((((QWidget *) parent())->geometry().size().width()-this->width())/2,0)); QPainter painter(this);
}*/
painter.fillRect(0,0,width(),height(),QColor("#BB000000"));
}
void PageLabelWidget::updatePosition() void PageLabelWidget::updatePosition()
{ {

View File

@ -10,11 +10,11 @@ class PageLabelWidget : public QWidget
{ {
Q_OBJECT Q_OBJECT
private: private:
QLabel * imgLabel;
QLabel * textLabel; QLabel * textLabel;
QPropertyAnimation * animation; QPropertyAnimation * animation;
//void resizeEvent(QResizeEvent * event); protected:
virtual void paintEvent(QPaintEvent *);
public: public:
PageLabelWidget(QWidget * parent); PageLabelWidget(QWidget * parent);