NOISSUE fix aspect ratio issues with the instance icon in the instance toolbar
This commit is contained in:
parent
c51512f940
commit
ea71281629
@ -392,20 +392,6 @@ QIcon IconList::getIcon(const QString &key) const
|
|||||||
return QIcon();
|
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
|
int IconList::getIconIndex(const QString &key) const
|
||||||
{
|
{
|
||||||
auto iter = name_index.find(key == "default" ? "infinity" : key);
|
auto iter = name_index.find(key == "default" ? "infinity" : key);
|
||||||
|
@ -38,7 +38,6 @@ public:
|
|||||||
virtual ~IconList() {};
|
virtual ~IconList() {};
|
||||||
|
|
||||||
QIcon getIcon(const QString &key) const;
|
QIcon getIcon(const QString &key) const;
|
||||||
QIcon getBigIcon(const QString &key) const;
|
|
||||||
int getIconIndex(const QString &key) const;
|
int getIconIndex(const QString &key) const;
|
||||||
|
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
@ -261,8 +261,7 @@ public:
|
|||||||
instanceToolBar->setObjectName(QStringLiteral("instanceToolBar"));
|
instanceToolBar->setObjectName(QStringLiteral("instanceToolBar"));
|
||||||
instanceToolBar->setEnabled(true);
|
instanceToolBar->setEnabled(true);
|
||||||
instanceToolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
|
instanceToolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
|
||||||
instanceToolBar->setIconSize(QSize(80, 80));
|
instanceToolBar->setToolButtonStyle(Qt::ToolButtonTextOnly);
|
||||||
instanceToolBar->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
|
||||||
instanceToolBar->setFloatable(false);
|
instanceToolBar->setFloatable(false);
|
||||||
MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar);
|
MainWindow->addToolBar(Qt::RightToolBarArea, instanceToolBar);
|
||||||
newsToolBar = new QToolBar(MainWindow);
|
newsToolBar = new QToolBar(MainWindow);
|
||||||
@ -275,7 +274,6 @@ public:
|
|||||||
MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar);
|
MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar);
|
||||||
|
|
||||||
mainToolBar->addAction(actionAddInstance);
|
mainToolBar->addAction(actionAddInstance);
|
||||||
mainToolBar->addAction(actionCopyInstance);
|
|
||||||
mainToolBar->addSeparator();
|
mainToolBar->addSeparator();
|
||||||
mainToolBar->addAction(actionViewInstanceFolder);
|
mainToolBar->addAction(actionViewInstanceFolder);
|
||||||
mainToolBar->addAction(actionViewCentralModsFolder);
|
mainToolBar->addAction(actionViewCentralModsFolder);
|
||||||
@ -294,7 +292,6 @@ public:
|
|||||||
mainToolBar->addAction(actionREDDIT);
|
mainToolBar->addAction(actionREDDIT);
|
||||||
mainToolBar->addAction(actionDISCORD);
|
mainToolBar->addAction(actionDISCORD);
|
||||||
mainToolBar->addAction(actionCAT);
|
mainToolBar->addAction(actionCAT);
|
||||||
instanceToolBar->addAction(actionChangeInstIcon);
|
|
||||||
instanceToolBar->addAction(actionLaunchInstance);
|
instanceToolBar->addAction(actionLaunchInstance);
|
||||||
instanceToolBar->addAction(actionLaunchInstanceOffline);
|
instanceToolBar->addAction(actionLaunchInstanceOffline);
|
||||||
instanceToolBar->addSeparator();
|
instanceToolBar->addSeparator();
|
||||||
@ -310,6 +307,7 @@ public:
|
|||||||
instanceToolBar->addSeparator();
|
instanceToolBar->addSeparator();
|
||||||
instanceToolBar->addAction(actionExportInstance);
|
instanceToolBar->addAction(actionExportInstance);
|
||||||
instanceToolBar->addAction(actionDeleteInstance);
|
instanceToolBar->addAction(actionDeleteInstance);
|
||||||
|
instanceToolBar->addAction(actionCopyInstance);
|
||||||
newsToolBar->addAction(actionMoreNews);
|
newsToolBar->addAction(actionMoreNews);
|
||||||
|
|
||||||
retranslateUi(MainWindow);
|
retranslateUi(MainWindow);
|
||||||
@ -411,6 +409,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
|||||||
// disabled until we have an instance selected
|
// disabled until we have an instance selected
|
||||||
ui->instanceToolBar->setEnabled(false);
|
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
|
// the rename label is inside the rename tool button
|
||||||
renameButton = new LabeledToolButton();
|
renameButton = new LabeledToolButton();
|
||||||
renameButton->setText("Instance Name");
|
renameButton->setText("Instance Name");
|
||||||
@ -615,22 +620,23 @@ void MainWindow::showInstanceContextMenu(const QPoint &pos)
|
|||||||
{
|
{
|
||||||
actions = ui->instanceToolBar->actions();
|
actions = ui->instanceToolBar->actions();
|
||||||
|
|
||||||
QAction *actionVoid = new QAction(m_selectedInstance->name(), this);
|
// replace the change icon widget with an actual action
|
||||||
actionVoid->setEnabled(false);
|
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);
|
QAction *actionRename = new QAction(tr("Rename"), this);
|
||||||
actionRename->setToolTip(ui->actionRenameInstance->toolTip());
|
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(actionRename, SIGNAL(triggered(bool)), SLOT(on_actionRenameInstance_triggered()));
|
||||||
connect(actionCopyInstance, SIGNAL(triggered(bool)), SLOT(on_actionCopyInstance_triggered()));
|
|
||||||
|
|
||||||
actions.replace(1, actionRename);
|
actions.replace(1, actionRename);
|
||||||
|
|
||||||
|
// add header
|
||||||
actions.prepend(actionSep);
|
actions.prepend(actionSep);
|
||||||
|
QAction *actionVoid = new QAction(m_selectedInstance->name(), this);
|
||||||
|
actionVoid->setEnabled(false);
|
||||||
actions.prepend(actionVoid);
|
actions.prepend(actionVoid);
|
||||||
actions.append(actionCopyInstance);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1187,8 +1193,9 @@ void MainWindow::on_actionChangeInstIcon_triggered()
|
|||||||
if (dlg.result() == QDialog::Accepted)
|
if (dlg.result() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
m_selectedInstance->setIconKey(dlg.selectedIconKey);
|
m_selectedInstance->setIconKey(dlg.selectedIconKey);
|
||||||
auto ico = MMC->icons()->getBigIcon(dlg.selectedIconKey);
|
auto icon = MMC->icons()->getIcon(dlg.selectedIconKey);
|
||||||
ui->actionChangeInstIcon->setIcon(ico);
|
ui->actionChangeInstIcon->setIcon(icon);
|
||||||
|
changeIconButton->setIcon(icon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1196,14 +1203,18 @@ void MainWindow::iconUpdated(QString icon)
|
|||||||
{
|
{
|
||||||
if (icon == m_currentInstIcon)
|
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)
|
void MainWindow::updateInstanceToolIcon(QString new_icon)
|
||||||
{
|
{
|
||||||
m_currentInstIcon = 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)
|
void MainWindow::setSelectedInstanceById(const QString &id)
|
||||||
|
@ -186,7 +186,7 @@ private:
|
|||||||
GroupView *view = nullptr;
|
GroupView *view = nullptr;
|
||||||
InstanceProxyModel *proxymodel = nullptr;
|
InstanceProxyModel *proxymodel = nullptr;
|
||||||
LabeledToolButton *renameButton = nullptr;
|
LabeledToolButton *renameButton = nullptr;
|
||||||
QToolButton *changeIconButton = nullptr;
|
LabeledToolButton *changeIconButton = nullptr;
|
||||||
QToolButton *newsLabel = nullptr;
|
QToolButton *newsLabel = nullptr;
|
||||||
QLabel *m_statusLeft = nullptr;
|
QLabel *m_statusLeft = nullptr;
|
||||||
ServerStatus *m_statusRight = nullptr;
|
ServerStatus *m_statusRight = nullptr;
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include <QStyleOption>
|
#include <QStyleOption>
|
||||||
#include "LabeledToolButton.h"
|
#include "LabeledToolButton.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@ -36,7 +37,7 @@ LabeledToolButton::LabeledToolButton(QWidget * parent)
|
|||||||
m_label->setAlignment(Qt::AlignCenter);
|
m_label->setAlignment(Qt::AlignCenter);
|
||||||
m_label->setTextInteractionFlags(Qt::NoTextInteraction);
|
m_label->setTextInteractionFlags(Qt::NoTextInteraction);
|
||||||
// somehow, this makes word wrap work in the QLabel. yay.
|
// somehow, this makes word wrap work in the QLabel. yay.
|
||||||
m_label->setMinimumWidth(100);
|
//m_label->setMinimumWidth(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString LabeledToolButton::text() const
|
QString LabeledToolButton::text() const
|
||||||
@ -49,6 +50,13 @@ void LabeledToolButton::setText(const QString & text)
|
|||||||
m_label->setText(text);
|
m_label->setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LabeledToolButton::setIcon(QIcon icon)
|
||||||
|
{
|
||||||
|
m_icon = icon;
|
||||||
|
resetIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\reimp
|
\reimp
|
||||||
*/
|
*/
|
||||||
@ -82,5 +90,32 @@ QSize LabeledToolButton::sizeHint() const
|
|||||||
void LabeledToolButton::resizeEvent(QResizeEvent * event)
|
void LabeledToolButton::resizeEvent(QResizeEvent * event)
|
||||||
{
|
{
|
||||||
m_label->setGeometry(QRect(4, 4, width()-8, height()-8));
|
m_label->setGeometry(QRect(4, 4, width()-8, height()-8));
|
||||||
|
if(!m_icon.isNull())
|
||||||
|
{
|
||||||
|
resetIcon();
|
||||||
|
}
|
||||||
QWidget::resizeEvent(event);
|
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
|
Q_OBJECT
|
||||||
|
|
||||||
QLabel * m_label;
|
QLabel * m_label;
|
||||||
|
QIcon m_icon;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LabeledToolButton(QWidget * parent = 0);
|
LabeledToolButton(QWidget * parent = 0);
|
||||||
|
|
||||||
QString text() const;
|
QString text() const;
|
||||||
void setText(const QString & text);
|
void setText(const QString & text);
|
||||||
|
void setIcon(QIcon icon);
|
||||||
virtual QSize sizeHint() const;
|
virtual QSize sizeHint() const;
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent * event);
|
void resizeEvent(QResizeEvent * event);
|
||||||
|
void resetIcon();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user