summaryrefslogtreecommitdiffstats
path: root/application/widgets
diff options
context:
space:
mode:
authorPetr Mrázek <peterix@gmail.com>2019-07-23 00:48:14 +0200
committerPetr Mrázek <peterix@gmail.com>2019-07-23 00:48:14 +0200
commitbf38021937a555249905d38cda0d4ea5fbc43fb3 (patch)
treec3b52577c1e0a1861330ff3312662148c96150aa /application/widgets
parent1e5b595923090bd19f4e5a04a5055b23e1e8678a (diff)
downloadMultiMC-bf38021937a555249905d38cda0d4ea5fbc43fb3.tar
MultiMC-bf38021937a555249905d38cda0d4ea5fbc43fb3.tar.gz
MultiMC-bf38021937a555249905d38cda0d4ea5fbc43fb3.tar.lz
MultiMC-bf38021937a555249905d38cda0d4ea5fbc43fb3.tar.xz
MultiMC-bf38021937a555249905d38cda0d4ea5fbc43fb3.zip
NOISSUE improve toolbars
Diffstat (limited to 'application/widgets')
-rw-r--r--application/widgets/WideBar.cpp59
-rw-r--r--application/widgets/WideBar.h18
2 files changed, 77 insertions, 0 deletions
diff --git a/application/widgets/WideBar.cpp b/application/widgets/WideBar.cpp
new file mode 100644
index 00000000..ee0a67e3
--- /dev/null
+++ b/application/widgets/WideBar.cpp
@@ -0,0 +1,59 @@
+#include "WideBar.h"
+#include <QToolButton>
+
+class ActionButton : public QToolButton
+{
+ Q_OBJECT
+public:
+ ActionButton(QAction * action, QWidget * parent = 0) : QToolButton(parent), m_action(action) {
+ setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
+ connect(action, &QAction::changed, this, &ActionButton::actionChanged);
+ connect(this, &ActionButton::clicked, action, &QAction::trigger);
+ actionChanged();
+ };
+private slots:
+ void actionChanged() {
+ setEnabled(m_action->isEnabled());
+ setChecked(m_action->isChecked());
+ setCheckable(m_action->isCheckable());
+ setText(m_action->text());
+ setIcon(m_action->icon());
+ setToolTip(m_action->toolTip());
+ setHidden(!m_action->isVisible());
+ }
+private:
+ QAction * m_action;
+};
+
+
+WideBar::WideBar(const QString& title, QWidget* parent) : QToolBar(title, parent)
+{
+ setFloatable(false);
+ setMovable(false);
+}
+
+WideBar::WideBar(QWidget* parent) : QToolBar(parent)
+{
+ setFloatable(false);
+ setMovable(false);
+}
+
+void WideBar::addAction(QAction* action)
+{
+ auto actionButton = new ActionButton(action, this);
+ auto newAction = addWidget(actionButton);
+ m_actionMap[action] = newAction;
+}
+
+void WideBar::insertSpacer(QAction* action)
+{
+ if(!m_actionMap.contains(action)) {
+ return;
+ }
+
+ QWidget* spacer = new QWidget();
+ spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+ insertWidget(m_actionMap[action], spacer);
+}
+
+#include "WideBar.moc"
diff --git a/application/widgets/WideBar.h b/application/widgets/WideBar.h
new file mode 100644
index 00000000..38da35d0
--- /dev/null
+++ b/application/widgets/WideBar.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#include <QToolBar>
+
+class WideBar : public QToolBar
+{
+ Q_OBJECT
+
+public:
+ explicit WideBar(const QString &title, QWidget * parent = nullptr);
+ explicit WideBar(QWidget * parent = nullptr);
+
+ void addAction(QAction *action);
+ void insertSpacer(QAction *action);
+
+private:
+ QMap<QAction *, QAction *> m_actionMap;
+};