|
Packit Bot |
052d53 |
/*
|
|
Packit Bot |
052d53 |
* Widget Showcase
|
|
Packit Bot |
052d53 |
* Copyright (C) 2014-2018 Martin Bříza <mbriza@redhat.com>
|
|
Packit Bot |
052d53 |
* Copyright (C) 2019 Jan Grulich <jgrulich@redhat.com>
|
|
Packit Bot |
052d53 |
*
|
|
Packit Bot |
052d53 |
* This program is free software; you can redistribute it and/or modify
|
|
Packit Bot |
052d53 |
* it under the terms of the GNU General Public License as published by
|
|
Packit Bot |
052d53 |
* the Free Software Foundation; either version 2 of the License, or
|
|
Packit Bot |
052d53 |
* (at your option) any later version.
|
|
Packit Bot |
052d53 |
*
|
|
Packit Bot |
052d53 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Bot |
052d53 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Bot |
052d53 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Bot |
052d53 |
* GNU General Public License for more details.
|
|
Packit Bot |
052d53 |
*
|
|
Packit Bot |
052d53 |
* You should have received a copy of the GNU General Public License along
|
|
Packit Bot |
052d53 |
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
Packit Bot |
052d53 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
Packit Bot |
052d53 |
*
|
|
Packit Bot |
052d53 |
*/
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include <QLayout>
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include "widgetfactory.h"
|
|
Packit Bot |
052d53 |
#include "ui_widgetfactory.h"
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
#include <QAction>
|
|
Packit Bot |
052d53 |
#include <QLineEdit>
|
|
Packit Bot |
052d53 |
#include <QMenu>
|
|
Packit Bot |
052d53 |
#include <QMenuBar>
|
|
Packit Bot |
052d53 |
#include <QToolBar>
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
class WidgetFactory::Private
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
public:
|
|
Packit Bot |
052d53 |
Private() { }
|
|
Packit Bot |
052d53 |
Ui_WidgetFactory ui;
|
|
Packit Bot |
052d53 |
};
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
WidgetFactory::WidgetFactory(QWidget *parent)
|
|
Packit Bot |
052d53 |
: QMainWindow(parent)
|
|
Packit Bot |
052d53 |
, d(new WidgetFactory::Private())
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
setGeometry(0, 0, 1440, 800);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
QWidget *mainWidget = new QWidget(this);
|
|
Packit Bot |
052d53 |
d->ui.setupUi(mainWidget);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
setCentralWidget(mainWidget);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// QLineEdit with the icon inside
|
|
Packit Bot |
052d53 |
QAction *lineEditAction = new QAction(QIcon::fromTheme(QLatin1String("view-refresh")), QString());
|
|
Packit Bot |
052d53 |
connect(lineEditAction, &QAction::triggered, this, [this] (bool checked) {
|
|
Packit Bot |
052d53 |
if (d->ui.linedit->echoMode() == QLineEdit::Normal) {
|
|
Packit Bot |
052d53 |
d->ui.linedit->setEchoMode(QLineEdit::Password);
|
|
Packit Bot |
052d53 |
} else {
|
|
Packit Bot |
052d53 |
d->ui.linedit->setEchoMode(QLineEdit::Normal);
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
});
|
|
Packit Bot |
052d53 |
d->ui.linedit->addAction(lineEditAction, QLineEdit::TrailingPosition);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// QLineEdit with the widget on the right side
|
|
Packit Bot |
052d53 |
connect(d->ui.button, &QPushButton::pressed, this, [this] () {
|
|
Packit Bot |
052d53 |
d->ui.lineedit2->clear();
|
|
Packit Bot |
052d53 |
});
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// Checkboxes
|
|
Packit Bot |
052d53 |
d->ui.checkbox3->setCheckState(Qt::PartiallyChecked);
|
|
Packit Bot |
052d53 |
d->ui.checkbox6->setCheckState(Qt::PartiallyChecked);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// Buttons
|
|
Packit Bot |
052d53 |
d->ui.pushbutton3->setDown(true);
|
|
Packit Bot |
052d53 |
d->ui.pushbutton4->setDown(true);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
// Sliders and progress bars
|
|
Packit Bot |
052d53 |
connect(d->ui.horizontalslider3, &QSlider::valueChanged, this, [this] (int value) {
|
|
Packit Bot |
052d53 |
d->ui.progressbar_horizontal->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.progressbar_horizontal2->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.progressbar_vertical->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.progressbar_vertical2->setValue(value);
|
|
Packit Bot |
052d53 |
});
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
connect(d->ui.horizontalslider, &QSlider::valueChanged, this, [this] (int value) {
|
|
Packit Bot |
052d53 |
d->ui.horizontalslider2->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.verticalslider->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.verticalslider2->setValue(value);
|
|
Packit Bot |
052d53 |
});
|
|
Packit Bot |
052d53 |
connect(d->ui.verticalslider, &QSlider::valueChanged, this, [this] (int value) {
|
|
Packit Bot |
052d53 |
d->ui.horizontalslider->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.horizontalslider2->setValue(value);
|
|
Packit Bot |
052d53 |
d->ui.verticalslider2->setValue(value);
|
|
Packit Bot |
052d53 |
});
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
QMenuBar *menubar = new QMenuBar(this);
|
|
Packit Bot |
052d53 |
setMenuBar(menubar);
|
|
Packit Bot |
052d53 |
// Inspired by Kondike (a gtk game)
|
|
Packit Bot |
052d53 |
QMenu *game = new QMenu("Game", menubar);
|
|
Packit Bot |
052d53 |
QAction *newGame = new QAction("New game");
|
|
Packit Bot |
052d53 |
newGame->setShortcut(QKeySequence::New);
|
|
Packit Bot |
052d53 |
game->addAction(newGame);
|
|
Packit Bot |
052d53 |
QAction *restart = new QAction("Restart");
|
|
Packit Bot |
052d53 |
restart->setDisabled(true);
|
|
Packit Bot |
052d53 |
game->addAction(restart);
|
|
Packit Bot |
052d53 |
QAction *statistics = new QAction("Statistics");
|
|
Packit Bot |
052d53 |
game->addAction(statistics);
|
|
Packit Bot |
052d53 |
QAction *selectGame = new QAction("Select game...");
|
|
Packit Bot |
052d53 |
selectGame->setShortcut(QKeySequence::Open);
|
|
Packit Bot |
052d53 |
game->addAction(selectGame);
|
|
Packit Bot |
052d53 |
QMenu *recentlyPlayed = new QMenu("Recently played");
|
|
Packit Bot |
052d53 |
recentlyPlayed->addAction(new QAction("Game 1", recentlyPlayed));
|
|
Packit Bot |
052d53 |
recentlyPlayed->addAction(new QAction("Game 1", recentlyPlayed));
|
|
Packit Bot |
052d53 |
game->addMenu(recentlyPlayed);
|
|
Packit Bot |
052d53 |
game->addSeparator();
|
|
Packit Bot |
052d53 |
QAction *close = new QAction("Close");
|
|
Packit Bot |
052d53 |
close->setShortcut(QKeySequence::Quit);
|
|
Packit Bot |
052d53 |
game->addAction(close);
|
|
Packit Bot |
052d53 |
menuBar()->insertMenu(nullptr, game);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
QMenu *edit = new QMenu("Edit", menubar);
|
|
Packit Bot |
052d53 |
QAction *act1 = new QAction("Pick me");
|
|
Packit Bot |
052d53 |
act1->setCheckable(true);
|
|
Packit Bot |
052d53 |
act1->setChecked(true);
|
|
Packit Bot |
052d53 |
QAction *act2 = new QAction("No, pick me instead");
|
|
Packit Bot |
052d53 |
act2->setCheckable(true);
|
|
Packit Bot |
052d53 |
QAction *act3 = new QAction("Don't pick me");
|
|
Packit Bot |
052d53 |
act3->setCheckable(true);
|
|
Packit Bot |
052d53 |
act3->setDisabled(true);
|
|
Packit Bot |
052d53 |
edit->addAction(act1);
|
|
Packit Bot |
052d53 |
edit->addAction(act2);
|
|
Packit Bot |
052d53 |
edit->addAction(act3);
|
|
Packit Bot |
052d53 |
QActionGroup *actionGroup = new QActionGroup(edit);
|
|
Packit Bot |
052d53 |
actionGroup->setExclusive(true);
|
|
Packit Bot |
052d53 |
actionGroup->addAction(act1);
|
|
Packit Bot |
052d53 |
actionGroup->addAction(act2);
|
|
Packit Bot |
052d53 |
actionGroup->addAction(act3);
|
|
Packit Bot |
052d53 |
menuBar()->insertMenu(nullptr, edit);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
menuBar()->insertMenu(nullptr, new QMenu("View", menubar));
|
|
Packit Bot |
052d53 |
QAction *testAction = new QAction(QStringLiteral("Test 1"));
|
|
Packit Bot |
052d53 |
testAction->setCheckable(true);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
edit->addAction(testAction);
|
|
Packit Bot |
052d53 |
menuBar()->insertMenu(nullptr, edit);
|
|
Packit Bot |
052d53 |
menuBar()->insertMenu(nullptr, new QMenu("Help"));
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
QToolBar *toolbar = new QToolBar();
|
|
Packit Bot |
052d53 |
toolbar->setMovable(false);
|
|
Packit Bot |
052d53 |
toolbar->setFloatable(false);
|
|
Packit Bot |
052d53 |
toolbar->addAction(QIcon::fromTheme("document-save"), "");
|
|
Packit Bot |
052d53 |
toolbar->addAction(QIcon::fromTheme("document-open"), "");
|
|
Packit Bot |
052d53 |
toolbar->addSeparator();
|
|
Packit Bot |
052d53 |
toolbar->addAction(QIcon::fromTheme("edit-find"), "");
|
|
Packit Bot |
052d53 |
QWidget *spacer = new QWidget;
|
|
Packit Bot |
052d53 |
spacer->setPalette(QPalette(Qt::transparent));
|
|
Packit Bot |
052d53 |
spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
Packit Bot |
052d53 |
toolbar->addWidget(spacer);
|
|
Packit Bot |
052d53 |
toolbar->addWidget(new QLineEdit("search..."));
|
|
Packit Bot |
052d53 |
addToolBar(Qt::TopToolBarArea, toolbar);
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
setWindowTitle(tr("Qt/GTK+ Widget Factory"));
|
|
Packit Bot |
052d53 |
}
|
|
Packit Bot |
052d53 |
|
|
Packit Bot |
052d53 |
WidgetFactory::~WidgetFactory()
|
|
Packit Bot |
052d53 |
{
|
|
Packit Bot |
052d53 |
delete d;
|
|
Packit Bot |
052d53 |
}
|