summaryrefslogtreecommitdiffstats
path: root/application/widgets/LabeledToolButton.cpp
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2017-09-28 02:47:54 +0200
committerPetr Mrázek <peterix@gmail.com>2017-09-28 02:47:54 +0200
commitea71281629706b4a8187108e4877b440e0e9b4df (patch)
tree6f3591acbbebc479efeff8cbf1ce679dc6f1d8f2 /application/widgets/LabeledToolButton.cpp
parentc51512f94036b7d13b98cb02b8e8c1e549e7b448 (diff)
downloadMultiMC-ea71281629706b4a8187108e4877b440e0e9b4df.tar
MultiMC-ea71281629706b4a8187108e4877b440e0e9b4df.tar.gz
MultiMC-ea71281629706b4a8187108e4877b440e0e9b4df.tar.lz
MultiMC-ea71281629706b4a8187108e4877b440e0e9b4df.tar.xz
MultiMC-ea71281629706b4a8187108e4877b440e0e9b4df.zip
NOISSUE fix aspect ratio issues with the instance icon in the instance toolbar
Diffstat (limited to 'application/widgets/LabeledToolButton.cpp')
-rw-r--r--application/widgets/LabeledToolButton.cpp37
1 files changed, 36 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 );
+ }
+}