summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--api/gui/icons/IconList.cpp14
-rw-r--r--api/gui/icons/IconList.h1
-rw-r--r--application/MainWindow.cpp45
-rw-r--r--application/MainWindow.h2
-rw-r--r--application/widgets/LabeledToolButton.cpp37
-rw-r--r--application/widgets/LabeledToolButton.h3
6 files changed, 68 insertions, 34 deletions
diff --git a/api/gui/icons/IconList.cpp b/api/gui/icons/IconList.cpp
index 3da0a8ea..aed96869 100644
--- a/api/gui/icons/IconList.cpp
+++ b/api/gui/icons/IconList.cpp
@@ -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);
diff --git a/api/gui/icons/IconList.h b/api/gui/icons/IconList.h
index 6a6e8b5c..41ec0bdd 100644
--- a/api/gui/icons/IconList.h
+++ b/api/gui/icons/IconList.h
@@ -38,7 +38,6 @@ public:
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;
diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp
index a6732cb0..70b88627 100644
--- a/application/MainWindow.cpp
+++ b/application/MainWindow.cpp
@@ -261,8 +261,7 @@ public:
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 @@ public:
MainWindow->addToolBar(Qt::BottomToolBarArea, newsToolBar);
mainToolBar->addAction(actionAddInstance);
- mainToolBar->addAction(actionCopyInstance);
mainToolBar->addSeparator();
mainToolBar->addAction(actionViewInstanceFolder);
mainToolBar->addAction(actionViewCentralModsFolder);
@@ -294,7 +292,6 @@ public:
mainToolBar->addAction(actionREDDIT);
mainToolBar->addAction(actionDISCORD);
mainToolBar->addAction(actionCAT);
- instanceToolBar->addAction(actionChangeInstIcon);
instanceToolBar->addAction(actionLaunchInstance);
instanceToolBar->addAction(actionLaunchInstanceOffline);
instanceToolBar->addSeparator();
@@ -310,6 +307,7 @@ public:
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,8 +1193,9 @@ 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);
}
}
@@ -1196,14 +1203,18 @@ 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)
diff --git a/application/MainWindow.h b/application/MainWindow.h
index 2a70f17c..1ed5f052 100644
--- a/application/MainWindow.h
+++ b/application/MainWindow.h
@@ -186,7 +186,7 @@ private:
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;
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();
};