qt-material-widgets/examples/appbarsettingseditor.cpp

85 lines
2.4 KiB
C++
Raw Permalink Normal View History

2017-10-11 17:16:52 +00:00
#include "appbarsettingseditor.h"
2017-10-11 19:25:22 +00:00
#include <QtWidgets/QVBoxLayout>
2017-10-11 19:44:35 +00:00
#include <QColorDialog>
2017-10-11 17:16:52 +00:00
#include <qtmaterialappbar.h>
2017-10-11 20:16:13 +00:00
#include <qtmaterialiconbutton.h>
2017-10-11 17:16:52 +00:00
#include <lib/qtmaterialtheme.h>
AppBarSettingsEditor::AppBarSettingsEditor(QWidget *parent)
: QWidget(parent),
ui(new Ui::AppBarSettingsForm),
2017-10-11 19:25:22 +00:00
m_appBar(new QtMaterialAppBar)
2017-10-11 17:16:52 +00:00
{
2017-10-11 20:51:49 +00:00
QLabel *label = new QLabel("Inbox");
label->setAttribute(Qt::WA_TranslucentBackground);
label->setForegroundRole(QPalette::Foreground);
label->setContentsMargins(6, 0, 0, 0);
QPalette palette = label->palette();
palette.setColor(label->foregroundRole(), Qt::white);
label->setPalette(palette);
label->setFont(QFont("Roboto", 18, QFont::Normal));
2017-10-11 20:16:13 +00:00
QtMaterialIconButton *button = new QtMaterialIconButton(QtMaterialTheme::icon("navigation", "menu"));
button->setIconSize(QSize(24, 24));
m_appBar->appBarLayout()->addWidget(button);
2017-10-11 20:51:49 +00:00
m_appBar->appBarLayout()->addWidget(label);
2017-10-11 20:16:13 +00:00
m_appBar->appBarLayout()->addStretch(1);
button->setColor(Qt::white);
button->setFixedWidth(42);
2017-10-11 20:16:13 +00:00
2017-10-11 17:16:52 +00:00
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
QWidget *widget = new QWidget;
layout->addWidget(widget);
QWidget *canvas = new QWidget;
canvas->setStyleSheet("QWidget { background: white; }");
layout->addWidget(canvas);
ui->setupUi(widget);
layout->setContentsMargins(20, 20, 20, 20);
layout = new QVBoxLayout;
canvas->setLayout(layout);
2017-10-11 19:44:35 +00:00
canvas->setMaximumHeight(300);
2017-10-11 17:16:52 +00:00
layout->addWidget(m_appBar);
2017-10-11 19:25:22 +00:00
layout->addStretch(1);
2017-10-11 17:16:52 +00:00
setupForm();
2017-10-11 19:44:35 +00:00
connect(ui->useThemeColorsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget()));
connect(ui->backgroundColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor()));
2017-10-11 17:16:52 +00:00
}
AppBarSettingsEditor::~AppBarSettingsEditor()
{
delete ui;
}
void AppBarSettingsEditor::setupForm()
{
2017-10-11 19:44:35 +00:00
ui->useThemeColorsCheckBox->setChecked(m_appBar->useThemeColors());
2017-10-11 17:16:52 +00:00
}
void AppBarSettingsEditor::updateWidget()
{
2017-10-11 19:44:35 +00:00
m_appBar->setUseThemeColors(ui->useThemeColorsCheckBox->isChecked());
}
void AppBarSettingsEditor::selectColor()
{
QColorDialog dialog;
if (dialog.exec()) {
QColor color = dialog.selectedColor();
QString senderName = sender()->objectName();
if ("backgroundColorToolButton" == senderName) {
m_appBar->setBackgroundColor(color);
ui->backgroundColorLineEdit->setText(color.name(QColor::HexRgb));
}
}
setupForm();
2017-10-11 17:16:52 +00:00
}