git-svn-id: svn://db.shs.com.ru/libs@464 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -61,7 +61,7 @@ void Ribbon::_resize() {
|
||||
|
||||
|
||||
void Ribbon::_setIconsSize() {
|
||||
qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
//qDebug() << "resize" << preferredIconSize() << QApplication::font();
|
||||
setTabIconSize(preferredIconSize(2, this));
|
||||
setIconSize(preferredIconSize(3, this));
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ QString uniqueName(QString n, const QStringList & names) {
|
||||
}
|
||||
|
||||
|
||||
int fontHeight(QWidget * w) {
|
||||
int fontHeight(const QWidget * w) {
|
||||
#ifdef Q_OS_ANDROID
|
||||
static int ret = QApplication::fontMetrics().size(0, "0").height();
|
||||
return ret;
|
||||
@@ -160,12 +160,12 @@ int fontHeight(QWidget * w) {
|
||||
}
|
||||
|
||||
|
||||
int lineThickness(QWidget * w) {
|
||||
int lineThickness(const QWidget * w) {
|
||||
return qMax<int>(qRound(fontHeight(w) / 15.), 1);
|
||||
}
|
||||
|
||||
|
||||
QSize preferredIconSize(float x, QWidget * w) {
|
||||
QSize preferredIconSize(float x, const QWidget * w) {
|
||||
int s = qMax<int>(8, qRound(fontHeight(w) * x));
|
||||
#ifdef Q_OS_MACOS
|
||||
s /= 1.25;
|
||||
@@ -174,6 +174,6 @@ QSize preferredIconSize(float x, QWidget * w) {
|
||||
}
|
||||
|
||||
|
||||
double appScale(QWidget * w) {
|
||||
double appScale(const QWidget * w) {
|
||||
return qMax<double>(fontHeight(w) / 15., 1.);
|
||||
}
|
||||
|
||||
@@ -118,10 +118,10 @@ inline QRectF enlargedRect(const QRectF & r, qreal dx, qreal dy, qreal v) {
|
||||
QVariant::Type typeFromLetter(const QString & l);
|
||||
QString uniqueName(QString n, const QStringList & names);
|
||||
|
||||
int fontHeight(QWidget * w = 0);
|
||||
int lineThickness(QWidget * w = 0);
|
||||
QSize preferredIconSize(float x = 1.f, QWidget * w = 0);
|
||||
double appScale(QWidget * w = 0);
|
||||
int fontHeight(const QWidget * w = 0);
|
||||
int lineThickness(const QWidget * w = 0);
|
||||
QSize preferredIconSize(float x = 1.f, const QWidget * w = 0);
|
||||
double appScale(const QWidget * w = 0);
|
||||
|
||||
|
||||
#endif // QAD_TYPES_H
|
||||
|
||||
59
qad/widgets/iconedlabel.cpp
Normal file
59
qad/widgets/iconedlabel.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include "iconedlabel.h"
|
||||
#include "qad_types.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QEvent>
|
||||
|
||||
|
||||
IconedLabel::IconedLabel(QWidget * parent): QFrame(parent) {
|
||||
label_.setAlignment(Qt::AlignCenter);
|
||||
icon_.setAlignment(Qt::AlignCenter);
|
||||
icon_.setScaledContents(true);
|
||||
setIconSize(QSize());
|
||||
setDirection(RightToLeft);
|
||||
}
|
||||
|
||||
|
||||
QIcon IconedLabel::icon() const {
|
||||
return icon_.pixmap() == 0 ? QIcon() : QIcon(*icon_.pixmap());
|
||||
}
|
||||
|
||||
|
||||
bool IconedLabel::event(QEvent * e) {
|
||||
if (e->type() == QEvent::FontChange || e->type() == QEvent::Polish)
|
||||
setIconSize(iconSize());
|
||||
return QFrame::event(e);
|
||||
}
|
||||
|
||||
|
||||
QSize IconedLabel::realIconSize() const {
|
||||
return size_.isValid() ? size_ : preferredIconSize(1.f, this);
|
||||
}
|
||||
|
||||
|
||||
void IconedLabel::setIcon(const QIcon & i) {
|
||||
sicon_ = i;
|
||||
setIconSize(iconSize());
|
||||
}
|
||||
|
||||
|
||||
void IconedLabel::setIconSize(const QSize & s) {
|
||||
size_ = s;
|
||||
QSize sz = realIconSize();
|
||||
icon_.setPixmap(sicon_.pixmap(sz));
|
||||
icon_.setFixedSize(sz);
|
||||
}
|
||||
|
||||
|
||||
void IconedLabel::setDirection(IconedLabel::Direction d) {
|
||||
dir_ = d;
|
||||
if (layout() != 0)
|
||||
delete layout();
|
||||
QLayout * lay = new QBoxLayout((QBoxLayout::Direction)dir_);
|
||||
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
lay->addWidget(&label_);
|
||||
lay->addWidget(&icon_);
|
||||
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(lay);
|
||||
update();
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
#include <QHBoxLayout>
|
||||
#include "qad_types.h"
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
@@ -21,42 +20,27 @@ class IconedLabel: public QFrame
|
||||
public:
|
||||
enum Direction {LeftToRight = 0, RightToLeft = 1, TopToBottom = 2, BottomToTop = 3};
|
||||
|
||||
explicit IconedLabel(QWidget * parent = 0): QFrame(parent) {
|
||||
label_.setAlignment(Qt::AlignCenter);
|
||||
icon_.setAlignment(Qt::AlignCenter);
|
||||
size_ = preferredIconSize(-1, this);
|
||||
setDirection(LeftToRight);
|
||||
}
|
||||
explicit IconedLabel(QWidget * parent = 0);
|
||||
|
||||
QString text() const {return label_.text();}
|
||||
QIcon icon() const {return icon_.pixmap() == 0 ? QIcon() : QIcon(*icon_.pixmap());}
|
||||
QIcon icon() const;
|
||||
QSize iconSize() const {return size_;}
|
||||
Direction direction() const {return dir_;}
|
||||
|
||||
protected:
|
||||
QLabel label_;
|
||||
QLabel icon_;
|
||||
virtual bool event(QEvent * e);
|
||||
QSize realIconSize() const;
|
||||
|
||||
QLabel label_, icon_;
|
||||
QIcon sicon_;
|
||||
QSize size_;
|
||||
Direction dir_;
|
||||
|
||||
public slots:
|
||||
void setText(const QString & t) {label_.setText(t);}
|
||||
void setIcon(const QIcon & i) {sicon_ = i; icon_.setPixmap(i.pixmap(size_));}
|
||||
void setIconSize(const QSize & s) {size_ = s; icon_.setPixmap(sicon_.pixmap(size_));}
|
||||
void setDirection(Direction d) {
|
||||
dir_ = d;
|
||||
if (layout() != 0)
|
||||
delete layout();
|
||||
QLayout * lay = new QBoxLayout((QBoxLayout::Direction)dir_);
|
||||
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
lay->addWidget(&label_);
|
||||
lay->addWidget(&icon_);
|
||||
lay->addItem(new QSpacerItem(1, 1, QSizePolicy::Expanding, QSizePolicy::Expanding));
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
setLayout(lay);
|
||||
update();
|
||||
}
|
||||
void setIcon(const QIcon & i);
|
||||
void setIconSize(const QSize & s);
|
||||
void setDirection(Direction d);
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user