summaryrefslogtreecommitdiffstats
path: root/examples/widgets/mainwindows/mainwindow/toolbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/widgets/mainwindows/mainwindow/toolbar.cpp')
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp88
1 files changed, 26 insertions, 62 deletions
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
index 280ba965d6..a9b308370a 100644
--- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
@@ -63,15 +63,15 @@ static QPixmap genIcon(const QSize &iconSize, int number, const QColor &color)
{ return genIcon(iconSize, QString::number(number), color); }
ToolBar::ToolBar(const QString &title, QWidget *parent)
- : QToolBar(parent), spinbox(0), spinboxAction(0)
+ : QToolBar(parent)
+ , spinbox(Q_NULLPTR)
+ , spinboxAction(Q_NULLPTR)
{
- tip = 0;
setWindowTitle(title);
setObjectName(title);
setIconSize(QSize(32, 32));
- QColor bg(palette().background().color());
menu = new QMenu("One", this);
menu->setIcon(genIcon(iconSize(), 1, Qt::black));
menu->addAction(genIcon(iconSize(), "A", Qt::blue), "A");
@@ -90,43 +90,43 @@ ToolBar::ToolBar(const QString &title, QWidget *parent)
addAction(genIcon(iconSize(), 6, Qt::yellow), "Six");
orderAction = new QAction(this);
orderAction->setText(tr("Order Items in Tool Bar"));
- connect(orderAction, SIGNAL(triggered()), SLOT(order()));
+ connect(orderAction, &QAction::triggered, this, &ToolBar::order);
randomizeAction = new QAction(this);
randomizeAction->setText(tr("Randomize Items in Tool Bar"));
- connect(randomizeAction, SIGNAL(triggered()), SLOT(randomize()));
+ connect(randomizeAction, &QAction::triggered, this, &ToolBar::randomize);
addSpinBoxAction = new QAction(this);
addSpinBoxAction->setText(tr("Add Spin Box"));
- connect(addSpinBoxAction, SIGNAL(triggered()), SLOT(addSpinBox()));
+ connect(addSpinBoxAction, &QAction::triggered, this, &ToolBar::addSpinBox);
removeSpinBoxAction = new QAction(this);
removeSpinBoxAction->setText(tr("Remove Spin Box"));
removeSpinBoxAction->setEnabled(false);
- connect(removeSpinBoxAction, SIGNAL(triggered()), SLOT(removeSpinBox()));
+ connect(removeSpinBoxAction, &QAction::triggered, this, &ToolBar::removeSpinBox);
movableAction = new QAction(tr("Movable"), this);
movableAction->setCheckable(true);
- connect(movableAction, SIGNAL(triggered(bool)), SLOT(changeMovable(bool)));
+ connect(movableAction, &QAction::triggered, this, &ToolBar::changeMovable);
allowedAreasActions = new QActionGroup(this);
allowedAreasActions->setExclusive(false);
allowLeftAction = new QAction(tr("Allow on Left"), this);
allowLeftAction->setCheckable(true);
- connect(allowLeftAction, SIGNAL(triggered(bool)), SLOT(allowLeft(bool)));
+ connect(allowLeftAction, &QAction::triggered, this, &ToolBar::allowLeft);
allowRightAction = new QAction(tr("Allow on Right"), this);
allowRightAction->setCheckable(true);
- connect(allowRightAction, SIGNAL(triggered(bool)), SLOT(allowRight(bool)));
+ connect(allowRightAction, &QAction::triggered, this, &ToolBar::allowRight);
allowTopAction = new QAction(tr("Allow on Top"), this);
allowTopAction->setCheckable(true);
- connect(allowTopAction, SIGNAL(triggered(bool)), SLOT(allowTop(bool)));
+ connect(allowTopAction, &QAction::triggered, this, &ToolBar::allowTop);
allowBottomAction = new QAction(tr("Allow on Bottom"), this);
allowBottomAction->setCheckable(true);
- connect(allowBottomAction, SIGNAL(triggered(bool)), SLOT(allowBottom(bool)));
+ connect(allowBottomAction, &QAction::triggered, this, &ToolBar::allowBottom);
allowedAreasActions->addAction(allowLeftAction);
allowedAreasActions->addAction(allowRightAction);
@@ -138,31 +138,28 @@ ToolBar::ToolBar(const QString &title, QWidget *parent)
leftAction = new QAction(tr("Place on Left") , this);
leftAction->setCheckable(true);
- connect(leftAction, SIGNAL(triggered(bool)), SLOT(placeLeft(bool)));
+ connect(leftAction, &QAction::triggered, this, &ToolBar::placeLeft);
rightAction = new QAction(tr("Place on Right") , this);
rightAction->setCheckable(true);
- connect(rightAction, SIGNAL(triggered(bool)), SLOT(placeRight(bool)));
+ connect(rightAction, &QAction::triggered, this, &ToolBar::placeRight);
topAction = new QAction(tr("Place on Top") , this);
topAction->setCheckable(true);
- connect(topAction, SIGNAL(triggered(bool)), SLOT(placeTop(bool)));
+ connect(topAction, &QAction::triggered, this, &ToolBar::placeTop);
bottomAction = new QAction(tr("Place on Bottom") , this);
bottomAction->setCheckable(true);
- connect(bottomAction, SIGNAL(triggered(bool)), SLOT(placeBottom(bool)));
+ connect(bottomAction, &QAction::triggered, this, &ToolBar::placeBottom);
areaActions->addAction(leftAction);
areaActions->addAction(rightAction);
areaActions->addAction(topAction);
areaActions->addAction(bottomAction);
- toolBarBreakAction = new QAction(tr("Insert break"), this);
- connect(toolBarBreakAction, SIGNAL(triggered(bool)), this, SLOT(insertToolBarBreak()));
+ connect(movableAction, &QAction::triggered, areaActions, &QActionGroup::setEnabled);
- connect(movableAction, SIGNAL(triggered(bool)), areaActions, SLOT(setEnabled(bool)));
-
- connect(movableAction, SIGNAL(triggered(bool)), allowedAreasActions, SLOT(setEnabled(bool)));
+ connect(movableAction, &QAction::triggered, allowedAreasActions, &QActionGroup::setEnabled);
menu = new QMenu(title, this);
menu->addAction(toggleViewAction());
@@ -179,9 +176,9 @@ ToolBar::ToolBar(const QString &title, QWidget *parent)
menu->addSeparator();
menu->addActions(areaActions->actions());
menu->addSeparator();
- menu->addAction(toolBarBreakAction);
+ menu->addAction(tr("Insert break"), this, &ToolBar::insertToolBarBreak);
- connect(menu, SIGNAL(aboutToShow()), this, SLOT(updateMenu()));
+ connect(menu, &QMenu::aboutToShow, this, &ToolBar::updateMenu);
randomize();
}
@@ -223,10 +220,9 @@ void ToolBar::updateMenu()
void ToolBar::order()
{
- QList<QAction *> ordered, actions1 = actions(),
- actions2 = findChildren<QAction *>();
- while (!actions2.isEmpty()) {
- QAction *action = actions2.takeFirst();
+ QList<QAction *> ordered;
+ QList<QAction *> actions1 = actions();
+ foreach (QAction *action, findChildren<QAction *>()) {
if (!actions1.contains(action))
continue;
actions1.removeAll(action);
@@ -241,7 +237,8 @@ void ToolBar::order()
void ToolBar::randomize()
{
- QList<QAction *> randomized, actions = this->actions();
+ QList<QAction *> randomized;
+ QList<QAction *> actions = this->actions();
while (!actions.isEmpty()) {
QAction *action = actions.takeAt(rand() % actions.size());
randomized.append(action);
@@ -254,9 +251,8 @@ void ToolBar::randomize()
void ToolBar::addSpinBox()
{
- if (!spinbox) {
+ if (!spinbox)
spinbox = new QSpinBox(this);
- }
if (!spinboxAction)
spinboxAction = addWidget(spinbox);
else
@@ -341,35 +337,3 @@ void ToolBar::insertToolBarBreak()
mainWindow->insertToolBarBreak(this);
}
-
-void ToolBar::enterEvent(QEvent*)
-{
-/*
- These labels on top of toolbars look darn ugly
-
- if (tip == 0) {
- tip = new QLabel(windowTitle(), this);
- QPalette pal = tip->palette();
- QColor c = Qt::black;
- c.setAlpha(100);
- pal.setColor(QPalette::Window, c);
- pal.setColor(QPalette::Foreground, Qt::white);
- tip->setPalette(pal);
- tip->setAutoFillBackground(true);
- tip->setMargin(3);
- tip->setText(windowTitle());
- }
- QPoint c = rect().center();
- QSize hint = tip->sizeHint();
- tip->setGeometry(c.x() - hint.width()/2, c.y() - hint.height()/2,
- hint.width(), hint.height());
-
- tip->show();
-*/
-}
-
-void ToolBar::leaveEvent(QEvent*)
-{
- if (tip != 0)
- tip->hide();
-}