diff options
author | Petr Mrázek <peterix@gmail.com> | 2017-09-28 02:47:54 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2017-09-28 02:47:54 +0200 |
commit | ea71281629706b4a8187108e4877b440e0e9b4df (patch) | |
tree | 6f3591acbbebc479efeff8cbf1ce679dc6f1d8f2 /application/widgets | |
parent | c51512f94036b7d13b98cb02b8e8c1e549e7b448 (diff) | |
download | PrismLauncher-ea71281629706b4a8187108e4877b440e0e9b4df.tar.gz PrismLauncher-ea71281629706b4a8187108e4877b440e0e9b4df.tar.bz2 PrismLauncher-ea71281629706b4a8187108e4877b440e0e9b4df.zip |
NOISSUE fix aspect ratio issues with the instance icon in the instance toolbar
Diffstat (limited to 'application/widgets')
-rw-r--r-- | application/widgets/LabeledToolButton.cpp | 37 | ||||
-rw-r--r-- | application/widgets/LabeledToolButton.h | 3 |
2 files changed, 39 insertions, 1 deletions
diff --git a/application/widgets/LabeledToolButton.cpp b/application/widgets/LabeledToolButton.cpp index 827fdf2d..b5b2f78e 100644 --- a/application/widgets/LabeledToolButton.cpp +++ b/application/widgets/LabeledToolButton.cpp @@ -19,6 +19,7 @@ #include <QStyleOption> #include "LabeledToolButton.h" #include <QApplication> +#include <QDebug> /* * @@ -36,7 +37,7 @@ LabeledToolButton::LabeledToolButton(QWidget * parent) m_label->setAlignment(Qt::AlignCenter); m_label->setTextInteractionFlags(Qt::NoTextInteraction); // somehow, this makes word wrap work in the QLabel. yay. - m_label->setMinimumWidth(100); + //m_label->setMinimumWidth(100); } QString LabeledToolButton::text() const @@ -49,6 +50,13 @@ void LabeledToolButton::setText(const QString & text) m_label->setText(text); } +void LabeledToolButton::setIcon(QIcon icon) +{ + m_icon = icon; + resetIcon(); +} + + /*! \reimp */ @@ -82,5 +90,32 @@ QSize LabeledToolButton::sizeHint() const void LabeledToolButton::resizeEvent(QResizeEvent * event) { m_label->setGeometry(QRect(4, 4, width()-8, height()-8)); + if(!m_icon.isNull()) + { + resetIcon(); + } QWidget::resizeEvent(event); } + +void LabeledToolButton::resetIcon() +{ + // prevent the label from changing our height + auto sizes = m_icon.availableSizes(); + if(sizes.count() > 0) + { + //auto maxSz = size(); + auto iconSz = sizes[0]; + float w = iconSz.width(); + float h = iconSz.height(); + float ar = w/h; + // FIXME: hardcoded max size of 160x80 + int newW = 80 * ar; + if(newW > 160) + newW = 160; + QSize newSz (newW, 80); + auto pixmap = m_icon.pixmap(newSz); + m_label->setPixmap(pixmap); + m_label->setMinimumHeight(80); + m_label->setSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Preferred ); + } +} diff --git a/application/widgets/LabeledToolButton.h b/application/widgets/LabeledToolButton.h index 999650fc..449d7fcc 100644 --- a/application/widgets/LabeledToolButton.h +++ b/application/widgets/LabeledToolButton.h @@ -25,13 +25,16 @@ class LabeledToolButton : public QToolButton Q_OBJECT QLabel * m_label; + QIcon m_icon; public: LabeledToolButton(QWidget * parent = 0); QString text() const; void setText(const QString & text); + void setIcon(QIcon icon); virtual QSize sizeHint() const; protected: void resizeEvent(QResizeEvent * event); + void resetIcon(); }; |