Permalink
Browse files

NOISSUE fix aspect ratio issues with the instance icon in the instanc…

…e toolbar
  • Loading branch information...
peterix committed Sep 28, 2017
1 parent c51512f commit ea71281629706b4a8187108e4877b440e0e9b4df
View
@@ -392,20 +392,6 @@ QIcon IconList::getIcon(const QString &key) const
return QIcon();
}
QIcon IconList::getBigIcon(const QString &key) const
{
int icon_index = getIconIndex(key);
// Fallback for icons that don't exist.
icon_index = getIconIndex(icon_index == -1 ? "infinity" : key);
if (icon_index == -1)
return QIcon();
QPixmap bigone = icons[icon_index].icon().pixmap(256,256).scaled(256,256);
return QIcon(bigone);
}
int IconList::getIconIndex(const QString &key) const
{
auto iter = name_index.find(key == "default" ? "infinity" : key);
View
@@ -38,7 +38,6 @@ class MULTIMC_GUI_EXPORT IconList : public QAbstractListModel, public IIconList
virtual ~IconList() {};
QIcon getIcon(const QString &key) const;
QIcon getBigIcon(const QString &key) const;
int getIconIndex(const QString &key) const;
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
View
@@ -261,8 +261,7 @@ class MainWindow::Ui
instanceToolBar->setObjectName(QStringLiteral("instanceToolBar"));
instanceToolBar->setEnabled(true);
instanceToolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
instanceToolBar->setIconSize(QSize(80, 80));
instanceToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
instanceToolBar->setToolButtonStyle(Qt::ToolButtonTextOnly);
instanceToolBar->setFloatable(false);
MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar);
newsToolBar = new QToolBar(MainWindow);
@@ -275,7 +274,6 @@ class MainWindow::Ui
MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar);
mainToolBar->addAction(actionAddInstance);
mainToolBar->addAction(actionCopyInstance);
mainToolBar->addSeparator();
mainToolBar->addAction(actionViewInstanceFolder);
mainToolBar->addAction(actionViewCentralModsFolder);
@@ -294,7 +292,6 @@ class MainWindow::Ui
mainToolBar->addAction(actionREDDIT);
mainToolBar->addAction(actionDISCORD);
mainToolBar->addAction(actionCAT);
instanceToolBar->addAction(actionChangeInstIcon);
instanceToolBar->addAction(actionLaunchInstance);
instanceToolBar->addAction(actionLaunchInstanceOffline);
instanceToolBar->addSeparator();
@@ -310,6 +307,7 @@ class MainWindow::Ui
instanceToolBar->addSeparator();
instanceToolBar->addAction(actionExportInstance);
instanceToolBar->addAction(actionDeleteInstance);
instanceToolBar->addAction(actionCopyInstance);
newsToolBar->addAction(actionMoreNews);
retranslateUi(MainWindow);
@@ -411,6 +409,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
// disabled until we have an instance selected
ui->instanceToolBar->setEnabled(false);
changeIconButton = new LabeledToolButton();
changeIconButton->setIcon(MMC->getThemedIcon("news"));
changeIconButton->setToolTip(ui->actionChangeInstIcon->toolTip());
connect(changeIconButton, SIGNAL(clicked(bool)), SLOT(on_actionChangeInstIcon_triggered()));
ui->instanceToolBar->insertWidget(ui->actionLaunchInstance, changeIconButton);
changeIconButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
// the rename label is inside the rename tool button
renameButton = new LabeledToolButton();
renameButton->setText("Instance Name");
@@ -615,22 +620,23 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
{
actions = ui->instanceToolBar->actions();
QAction *actionVoid = new QAction(m_selectedInstance->name(), this);
actionVoid->setEnabled(false);
// replace the change icon widget with an actual action
QAction *actionChangeIcon = new QAction(tr("Change Icon"), this);
actionChangeIcon->setToolTip(ui->actionRenameInstance->toolTip());
connect(actionChangeIcon, SIGNAL(triggered(bool)), SLOT(on_actionChangeInstIcon_triggered()));
actions.replace(0, actionChangeIcon);
// replace the rename widget with an actual action
QAction *actionRename = new QAction(tr("Rename"), this);
actionRename->setToolTip(ui->actionRenameInstance->toolTip());
QAction *actionCopyInstance = new QAction(tr("Copy instance"), this);
actionCopyInstance->setToolTip(ui->actionCopyInstance->toolTip());
connect(actionRename, SIGNAL(triggered(bool)), SLOT(on_actionRenameInstance_triggered()));
connect(actionCopyInstance, SIGNAL(triggered(bool)), SLOT(on_actionCopyInstance_triggered()));
actions.replace(1, actionRename);
// add header
actions.prepend(actionSep);
QAction *actionVoid = new QAction(m_selectedInstance->name(), this);
actionVoid->setEnabled(false);
actions.prepend(actionVoid);
actions.append(actionCopyInstance);
}
else
{
@@ -1187,23 +1193,28 @@ void MainWindow::on_actionChangeInstIcon_triggered()
if (dlg.result() == QDialog::Accepted)
{
m_selectedInstance->setIconKey(dlg.selectedIconKey);
auto ico = MMC->icons()->getBigIcon(dlg.selectedIconKey);
ui->actionChangeInstIcon->setIcon(ico);
auto icon = MMC->icons()->getIcon(dlg.selectedIconKey);
ui->actionChangeInstIcon->setIcon(icon);
changeIconButton->setIcon(icon);
}
}
void MainWindow::iconUpdated(QString icon)
{
if (icon == m_currentInstIcon)
{
ui->actionChangeInstIcon->setIcon(MMC->icons()->getBigIcon(m_currentInstIcon));
auto icon = MMC->icons()->getIcon(m_currentInstIcon);
ui->actionChangeInstIcon->setIcon(icon);
changeIconButton->setIcon(icon);
}
}
void MainWindow::updateInstanceToolIcon(QString new_icon)
{
m_currentInstIcon = new_icon;
ui->actionChangeInstIcon->setIcon(MMC->icons()->getBigIcon(m_currentInstIcon));
auto icon = MMC->icons()->getIcon(m_currentInstIcon);
ui->actionChangeInstIcon->setIcon(icon);
changeIconButton->setIcon(icon);
}
void MainWindow::setSelectedInstanceById(const QString &id)
View
@@ -186,7 +186,7 @@ private slots:
GroupView *view = nullptr;
InstanceProxyModel *proxymodel = nullptr;
LabeledToolButton *renameButton = nullptr;
QToolButton *changeIconButton = nullptr;
LabeledToolButton *changeIconButton = nullptr;
QToolButton *newsLabel = nullptr;
QLabel *m_statusLeft = nullptr;
ServerStatus *m_statusRight = nullptr;
@@ -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 );
}
}
@@ -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();
};

0 comments on commit ea71281

Please sign in to comment.