diff --git a/examples/avatarsettingseditor.cpp b/examples/avatarsettingseditor.cpp new file mode 100644 index 0000000..7affc29 --- /dev/null +++ b/examples/avatarsettingseditor.cpp @@ -0,0 +1,104 @@ +#include "avatarsettingseditor.h" +#include +#include "qtmaterialavatar.h" + +AvatarSettingsEditor::AvatarSettingsEditor(QWidget *parent) + : QWidget(parent), + ui(new Ui::AvatarSettingsForm), + m_avatar(new QtMaterialAvatar(QChar('X'))) +{ + 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); + layout->addWidget(m_avatar); + layout->setAlignment(m_avatar, Qt::AlignCenter); + + setupForm(); + + connect(ui->disabledCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget())); + connect(ui->useThemeColorsCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateWidget())); + connect(ui->sizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateWidget())); + connect(ui->typeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateWidget())); + connect(ui->backgroundColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor())); + connect(ui->textColorToolButton, SIGNAL(pressed()), this, SLOT(selectColor())); + + ui->sizeSpinBox->setRange(5, 300); +} + +AvatarSettingsEditor::~AvatarSettingsEditor() +{ + delete ui; +} + +void AvatarSettingsEditor::setupForm() +{ + switch (m_avatar->type()) + { + case Material::LetterAvatar: + ui->typeComboBox->setCurrentIndex(0); + break; + case Material::ImageAvatar: + ui->typeComboBox->setCurrentIndex(1); + break; + case Material::IconAvatar: + ui->typeComboBox->setCurrentIndex(2); + break; + default: + break; + } + + ui->disabledCheckBox->setChecked(!m_avatar->isEnabled()); + ui->useThemeColorsCheckBox->setChecked(m_avatar->useThemeColors()); + ui->sizeSpinBox->setValue(m_avatar->size()); +} + +void AvatarSettingsEditor::updateWidget() +{ + switch (ui->typeComboBox->currentIndex()) + { + case 0: + m_avatar->setLetter(QChar('X')); + break; + case 1: + m_avatar->setImage(QImage(":/images/assets/sikh.jpg")); + break; + case 2: + m_avatar->setIcon(QIcon(":/icons/assets/ic_message_24px.svg")); + break; + default: + break; + } + + m_avatar->setDisabled(ui->disabledCheckBox->isChecked()); + m_avatar->setUseThemeColors(ui->useThemeColorsCheckBox->isChecked()); + m_avatar->setSize(ui->sizeSpinBox->value()); +} + +void AvatarSettingsEditor::selectColor() +{ + QColorDialog dialog; + if (dialog.exec()) { + QColor color = dialog.selectedColor(); + QString senderName = sender()->objectName(); + if ("textColorToolButton" == senderName) { + m_avatar->setTextColor(color); + ui->textColorLineEdit->setText(color.name(QColor::HexRgb)); + } else if ("backgroundColorToolButton" == senderName) { + m_avatar->setBackgroundColor(color); + ui->backgroundColorLineEdit->setText(color.name(QColor::HexRgb)); + } + } + setupForm(); +} diff --git a/examples/avatarsettingseditor.h b/examples/avatarsettingseditor.h new file mode 100644 index 0000000..c9bc009 --- /dev/null +++ b/examples/avatarsettingseditor.h @@ -0,0 +1,27 @@ +#ifndef AVATARSETTINGSEDITOR_H +#define AVATARSETTINGSEDITOR_H + +#include +#include "ui_avatarsettingsform.h" + +class QtMaterialAvatar; + +class AvatarSettingsEditor : public QWidget +{ + Q_OBJECT + +public: + explicit AvatarSettingsEditor(QWidget *parent = 0); + ~AvatarSettingsEditor(); + +protected slots: + void setupForm(); + void updateWidget(); + void selectColor(); + +private: + Ui::AvatarSettingsForm *const ui; + QtMaterialAvatar *const m_avatar; +}; + +#endif // AVATARSETTINGSEDITOR_H diff --git a/examples/avatarsettingsform.ui b/examples/avatarsettingsform.ui new file mode 100644 index 0000000..2124cf8 --- /dev/null +++ b/examples/avatarsettingsform.ui @@ -0,0 +1,137 @@ + + + AvatarSettingsForm + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + 0 + 0 + 221 + 231 + + + + + + + Use theme colors + + + + + + + + + + Text color + + + + + + + + + false + + + + + + + ... + + + + + + + + + Background color + + + + + + + + + false + + + + + + + ... + + + + + + + + + Size + + + + + + + + + + Type + + + + + + + + Letter + + + + + Image + + + + + Icon + + + + + + + + Disabled + + + + + + + + + + + + diff --git a/examples/examples.pro b/examples/examples.pro index 812ce56..9496e51 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,8 +1,15 @@ QT += core gui widgets TEMPLATE = app -SOURCES = mainwindow.cpp main.cpp -HEADERS = mainwindow.h +SOURCES = \ + mainwindow.cpp \ + main.cpp \ + avatarsettingseditor.cpp +HEADERS = \ + mainwindow.h \ + avatarsettingseditor.h LIBS += ../components/libcomponents.a INCLUDEPATH += ../components/ TARGET = ../examples-exe -RESOURCES += resources.qrc +RESOURCES += resources.qrc +FORMS += \ + avatarsettingsform.ui diff --git a/examples/mainwindow.cpp b/examples/mainwindow.cpp index 4e6f08f..d78abf6 100644 --- a/examples/mainwindow.cpp +++ b/examples/mainwindow.cpp @@ -1,10 +1,12 @@ #include "mainwindow.h" #include #include +#include "avatarsettingseditor.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { + /* QtMaterialAvatar *avatars[3]; avatars[0] = new QtMaterialAvatar(QImage("../qt-material-widgets/examples/assets/uxceo-128.jpg")); avatars[1] = new QtMaterialAvatar('W'); @@ -19,6 +21,10 @@ MainWindow::MainWindow(QWidget *parent) layout->addWidget(avatars[0]); layout->addWidget(avatars[1]); layout->addWidget(avatars[2]); + */ + + AvatarSettingsEditor *editor = new AvatarSettingsEditor; + setCentralWidget(editor); } MainWindow::~MainWindow() diff --git a/examples/resources.qrc b/examples/resources.qrc index 4bed9d1..61c4629 100644 --- a/examples/resources.qrc +++ b/examples/resources.qrc @@ -2,4 +2,7 @@ assets/ic_message_24px.svg + + assets/sikh.jpg +