Add tStatusFrame

This commit is contained in:
Victor Tran 2020-04-22 22:18:09 +10:00
parent 8c59d5d8ae
commit 44b03e431b
No known key found for this signature in database
GPG key ID: FBA10B22D602BAC1
5 changed files with 219 additions and 1 deletions

View file

@ -78,6 +78,7 @@ SOURCES += tvariantanimation.cpp \
tpropertyanimation.cpp \
thelibsglobal.cpp \
tsettings.cpp \
tstatusframe.cpp \
ttitlelabel.cpp \
ttoast.cpp \
tvirtualkeyboard.cpp \
@ -106,6 +107,7 @@ HEADERS += tvariantanimation.h\
tlocale.h \
tpropertyanimation.h \
tsettings.h \
tstatusframe.h \
ttitlelabel.h \
ttoast.h \
tnotification.h \
@ -191,7 +193,8 @@ DISTFILES += \
FORMS += \
taboutdialog.ui \
tcsdtools/csdbuttonbox.ui \
tshortcuthud.ui
tshortcuthud.ui \
tstatusframe.ui
RESOURCES += \
thelibs_icons.qrc \

View file

@ -93,7 +93,11 @@ QStringList tSettings::delimitedList(QString key) {
QStringList tSettings::childGroups() {
QSet<QString> groups;
for (QSharedPointer<QSettings> settings : d->allSettings) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
groups.unite(settings->childGroups().toSet());
#else
groups.unite(QSet<QString>(settings->childGroups().begin(), settings->childGroups().end()));
#endif
}
return groups.values();
}
@ -101,7 +105,11 @@ QStringList tSettings::childGroups() {
QStringList tSettings::childKeys() {
QSet<QString> groups;
for (QSharedPointer<QSettings> settings : d->allSettings) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
groups.unite(settings->childKeys().toSet());
#else
groups.unite(QSet<QString>(settings->childKeys().begin(), settings->childKeys().end()));
#endif
}
return groups.values();
}

90
lib/tstatusframe.cpp Normal file
View file

@ -0,0 +1,90 @@
/****************************************
*
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
* Copyright (C) 2020 Victor Tran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
#include "tstatusframe.h"
#include "ui_tstatusframe.h"
struct tStatusFramePrivate {
QString title;
QString text;
tStatusFrame::State state = tStatusFrame::NoState;
};
tStatusFrame::tStatusFrame(QWidget* parent) :
QFrame(parent),
ui(new Ui::tStatusFrame) {
ui->setupUi(this);
d = new tStatusFramePrivate();
}
tStatusFrame::~tStatusFrame() {
delete ui;
delete d;
}
QString tStatusFrame::title() const {
return d->title;
}
void tStatusFrame::setTitle(const QString& value) {
d->title = value;
ui->titleLabel->setText(value.toUpper());
emit titleChanged();
}
QString tStatusFrame::text() const {
return d->text;
}
void tStatusFrame::setText(const QString& value) {
d->text = value;
ui->textLabel->setText(value);
emit textChanged();
}
tStatusFrame::State tStatusFrame::state() const {
return d->state;
}
void tStatusFrame::setState(const tStatusFrame::State& state) {
d->state = state;
QPalette pal = QApplication::palette(this);
switch (state) {
case NoState:
break;
case Good:
pal.setColor(QPalette::Window, QColor(0, 100, 0));
pal.setColor(QPalette::WindowText, Qt::white);
break;
case Warning:
pal.setColor(QPalette::Window, QColor(200, 100, 0));
pal.setColor(QPalette::WindowText, Qt::white);
break;
case Error:
pal.setColor(QPalette::Window, QColor(100, 0, 0));
pal.setColor(QPalette::WindowText, Qt::white);
}
this->setPalette(pal);
emit stateChanged();
}

67
lib/tstatusframe.h Normal file
View file

@ -0,0 +1,67 @@
/****************************************
*
* INSERT-PROJECT-NAME-HERE - INSERT-GENERIC-NAME-HERE
* Copyright (C) 2020 Victor Tran
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
#ifndef TSTATUSFRAME_H
#define TSTATUSFRAME_H
#include "the-libs_global.h"
#include <QFrame>
namespace Ui {
class tStatusFrame;
}
struct tStatusFramePrivate;
class THELIBSSHARED_EXPORT tStatusFrame : public QFrame {
Q_OBJECT
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
public:
explicit tStatusFrame(QWidget* parent = nullptr);
~tStatusFrame();
enum State {
NoState,
Good,
Warning,
Error
};
QString title() const;
void setTitle(const QString& value);
QString text() const;
void setText(const QString& value);
State state() const;
void setState(const State& state);
signals:
void titleChanged();
void textChanged();
void stateChanged();
private:
Ui::tStatusFrame* ui;
tStatusFramePrivate* d;
};
#endif // TSTATUSFRAME_H

50
lib/tstatusframe.ui Normal file
View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>tStatusFrame</class>
<widget class="QFrame" name="tStatusFrame">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>60</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Frame</string>
</property>
<property name="autoFillBackground">
<bool>true</bool>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="titleLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">TextLabel</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="textLabel">
<property name="text">
<string notr="true">TextLabel</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>