1
0
Fork 0
mirror of https://github.com/eliboa/TegraRcmGUI.git synced 2024-11-25 03:32:05 +00:00
TegraRcmGUI/qutils.h

103 lines
2.3 KiB
C
Raw Normal View History

2020-06-24 19:30:39 +01:00
#ifndef QUTILS_H
#define QUTILS_H
#include <QWidget>
#include <QFileDialog>
#include <QFile>
#include <QSettings>
2020-06-24 19:31:54 +01:00
#include <QLocale>
#include <QtWidgets>
2020-06-24 19:30:39 +01:00
enum fdMode { open_file, save_as };
QString FileDialog(QWidget *parent, fdMode mode, const QString& defaultName = "");
2020-06-24 19:31:54 +01:00
QString GetReadableSize(qint64 bytes);
QString GetStyleSheetFromResFile(QString qss_file);
class Switch : public QAbstractButton {
Q_OBJECT
Q_PROPERTY(int offset READ offset WRITE setOffset)
Q_PROPERTY(QBrush brush READ brush WRITE setBrush)
public:
Switch(bool initial_state, int width, QBrush brush = QBrush("#009688"), QWidget* parent = nullptr);
Switch(const QBrush& brush, QWidget* parent = nullptr);
QSize sizeHint() const override;
QBrush brush() const {
return _brush;
}
void setBrush(const QBrush &brsh) {
_brush = brsh;
}
int offset() const {
return _x;
}
void setOffset(int o) {
_x = o;
update();
}
bool isActive() { return _switch; }
bool getState() { return _switch; }
2020-06-24 19:31:54 +01:00
void setState(bool value) { _switch = value; }
void toggle();
2020-06-24 19:31:54 +01:00
protected:
void paintEvent(QPaintEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override;
void enterEvent(QEvent*) override;
private:
bool _switch;
qreal _opacity;
int _x, _y, _height, _margin, _width;
QBrush _thumb, _track, _brush;
QPropertyAnimation *_anim = nullptr;
};
class AnimatedLabel : public QLabel
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor)
public:
AnimatedLabel(QWidget *parent = 0)
{
}
void setColor (QColor color){
setStyleSheet(QString(
"qproperty-alignment: 'AlignVCenter | AlignRight';"
"background-color: rgba(%1, %2, %3, 200);"
"color: rgb(0, 0, 0);"
"border-top-left-radius: 20px; "
"border-bottom-left-radius: 20px; "
"padding: 10px;").arg(color.red()).arg(color.green()).arg(color.blue()));
}
QColor color(){
return Qt::black; // getter is not really needed for now
}
};
class MoveWindowWidget : public QWidget
{
Q_OBJECT
public:
explicit MoveWindowWidget(QWidget *parent = nullptr);
protected:
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
QPoint startPos;
};
2020-06-24 19:30:39 +01:00
#endif // QUTILS_H