feat: add some helping methods to WideBar
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
05fa266e6b
commit
032ceefa1d
@ -76,13 +76,20 @@ void WideBar::addSeparator()
|
||||
m_entries.push_back(entry);
|
||||
}
|
||||
|
||||
void WideBar::insertActionBefore(QAction* before, QAction* action){
|
||||
auto iter = std::find_if(m_entries.begin(), m_entries.end(), [before](BarEntry * entry) {
|
||||
return entry->wideAction == before;
|
||||
auto WideBar::getMatching(QAction* act) -> QList<BarEntry*>::iterator
|
||||
{
|
||||
auto iter = std::find_if(m_entries.begin(), m_entries.end(), [act](BarEntry * entry) {
|
||||
return entry->wideAction == act;
|
||||
});
|
||||
if(iter == m_entries.end()) {
|
||||
|
||||
return iter;
|
||||
}
|
||||
|
||||
void WideBar::insertActionBefore(QAction* before, QAction* action){
|
||||
auto iter = getMatching(before);
|
||||
if(iter == m_entries.end())
|
||||
return;
|
||||
}
|
||||
|
||||
auto entry = new BarEntry();
|
||||
entry->qAction = insertWidget((*iter)->qAction, new ActionButton(action, this));
|
||||
entry->wideAction = action;
|
||||
@ -90,14 +97,24 @@ void WideBar::insertActionBefore(QAction* before, QAction* action){
|
||||
m_entries.insert(iter, entry);
|
||||
}
|
||||
|
||||
void WideBar::insertActionAfter(QAction* after, QAction* action){
|
||||
auto iter = getMatching(after);
|
||||
if(iter == m_entries.end())
|
||||
return;
|
||||
|
||||
auto entry = new BarEntry();
|
||||
entry->qAction = insertWidget((*(iter+1))->qAction, new ActionButton(action, this));
|
||||
entry->wideAction = action;
|
||||
entry->type = BarEntry::Action;
|
||||
m_entries.insert(iter + 1, entry);
|
||||
}
|
||||
|
||||
void WideBar::insertSpacer(QAction* action)
|
||||
{
|
||||
auto iter = std::find_if(m_entries.begin(), m_entries.end(), [action](BarEntry * entry) {
|
||||
return entry->wideAction == action;
|
||||
});
|
||||
if(iter == m_entries.end()) {
|
||||
auto iter = getMatching(action);
|
||||
if(iter == m_entries.end())
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget* spacer = new QWidget();
|
||||
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
|
||||
@ -107,6 +124,18 @@ void WideBar::insertSpacer(QAction* action)
|
||||
m_entries.insert(iter, entry);
|
||||
}
|
||||
|
||||
void WideBar::insertSeparator(QAction* before)
|
||||
{
|
||||
auto iter = getMatching(before);
|
||||
if(iter == m_entries.end())
|
||||
return;
|
||||
|
||||
auto entry = new BarEntry();
|
||||
entry->qAction = QToolBar::insertSeparator(before);
|
||||
entry->type = BarEntry::Separator;
|
||||
m_entries.insert(iter, entry);
|
||||
}
|
||||
|
||||
QMenu * WideBar::createContextMenu(QWidget *parent, const QString & title)
|
||||
{
|
||||
QMenu *contextMenu = new QMenu(title, parent);
|
||||
|
@ -1,27 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QAction>
|
||||
#include <QMap>
|
||||
#include <QToolBar>
|
||||
|
||||
class QMenu;
|
||||
|
||||
class WideBar : public QToolBar
|
||||
{
|
||||
class WideBar : public QToolBar {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WideBar(const QString &title, QWidget * parent = nullptr);
|
||||
explicit WideBar(QWidget * parent = nullptr);
|
||||
public:
|
||||
explicit WideBar(const QString& title, QWidget* parent = nullptr);
|
||||
explicit WideBar(QWidget* parent = nullptr);
|
||||
virtual ~WideBar();
|
||||
|
||||
void addAction(QAction *action);
|
||||
void addAction(QAction* action);
|
||||
void addSeparator();
|
||||
void insertSpacer(QAction *action);
|
||||
void insertActionBefore(QAction *before, QAction *action);
|
||||
QMenu *createContextMenu(QWidget *parent = nullptr, const QString & title = QString());
|
||||
|
||||
private:
|
||||
void insertSpacer(QAction* action);
|
||||
void insertSeparator(QAction* before);
|
||||
void insertActionBefore(QAction* before, QAction* action);
|
||||
void insertActionAfter(QAction* after, QAction* action);
|
||||
|
||||
QMenu* createContextMenu(QWidget* parent = nullptr, const QString& title = QString());
|
||||
|
||||
private:
|
||||
struct BarEntry;
|
||||
QList<BarEntry *> m_entries;
|
||||
|
||||
auto getMatching(QAction* act) -> QList<BarEntry*>::iterator;
|
||||
|
||||
private:
|
||||
QList<BarEntry*> m_entries;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user