diff options
Diffstat (limited to 'test/darkbutton')
-rw-r--r-- | test/darkbutton/DarkButton.cpp | 99 | ||||
-rw-r--r-- | test/darkbutton/DarkButton.h | 22 | ||||
-rw-r--r-- | test/darkbutton/MainWindow.cpp | 41 | ||||
-rw-r--r-- | test/darkbutton/MainWindow.h | 26 | ||||
-rw-r--r-- | test/darkbutton/MainWindow.ui | 26 | ||||
-rw-r--r-- | test/darkbutton/cancelDarkD.png | bin | 0 -> 151 bytes | |||
-rw-r--r-- | test/darkbutton/cancelDarkE.png | bin | 0 -> 473 bytes | |||
-rw-r--r-- | test/darkbutton/darkButton.png | bin | 0 -> 3969 bytes | |||
-rw-r--r-- | test/darkbutton/darkButtonOver.png | bin | 0 -> 4286 bytes | |||
-rw-r--r-- | test/darkbutton/darkButtonPushed.png | bin | 0 -> 3903 bytes | |||
-rw-r--r-- | test/darkbutton/darkbutton.pro | 38 | ||||
-rw-r--r-- | test/darkbutton/main.cpp | 11 | ||||
-rw-r--r-- | test/darkbutton/res.qrc | 9 |
13 files changed, 272 insertions, 0 deletions
diff --git a/test/darkbutton/DarkButton.cpp b/test/darkbutton/DarkButton.cpp new file mode 100644 index 0000000..b785961 --- /dev/null +++ b/test/darkbutton/DarkButton.cpp @@ -0,0 +1,99 @@ +#include "DarkButton.h" +#include <QPainter> + +DarkButton::DarkButton(QWidget *parent) : + QPushButton(parent) +{ + setMinimumHeight(36); + setMaximumHeight(36); + setStyleSheet("border:none;color:#afb;"); + over=false; + enabled=true; +} + +void DarkButton::paintEvent(QPaintEvent * event) +{ + if(backgroundLeft.isNull() || backgroundLeft.height()!=height()) + { + QPixmap background(":/darkButton.png"); + if(background.isNull()) + abort(); + QPixmap backgroundPushed(":/darkButtonPushed.png"); + if(backgroundPushed.isNull()) + abort(); + QPixmap over(":/darkButtonOver.png"); + if(over.isNull()) + abort(); + if(height()==background.height()) + { + backgroundLeft=background.copy(0,0,10,36); + backgroundMiddle=background.copy(10,0,46,36); + backgroundRight=background.copy(56,0,10,36); + backgroundPushedLeft=backgroundPushed.copy(0,0,10,36); + backgroundPushedMiddle=backgroundPushed.copy(10,0,46,36); + backgroundPushedRight=backgroundPushed.copy(56,0,10,36); + overLeft=over.copy(0,0,10,36); + overMiddle=over.copy(10,0,46,36); + overRight=over.copy(56,0,10,36); + } + else + { + backgroundLeft=background.copy(0,0,10,36).scaledToHeight(height(),Qt::SmoothTransformation); + backgroundMiddle=background.copy(10,0,46,36).scaledToHeight(height(),Qt::SmoothTransformation); + backgroundRight=background.copy(56,0,10,36).scaledToHeight(height(),Qt::SmoothTransformation); + backgroundPushedLeft=backgroundPushed.copy(0,0,10,36).scaledToHeight(height(),Qt::SmoothTransformation); + backgroundPushedMiddle=backgroundPushed.copy(10,0,46,36).scaledToHeight(height(),Qt::SmoothTransformation); + backgroundPushedRight=backgroundPushed.copy(56,0,10,36).scaledToHeight(height(),Qt::SmoothTransformation); + overLeft=over.copy(0,0,10,36).scaledToHeight(height(),Qt::SmoothTransformation); + overMiddle=over.copy(10,0,46,36).scaledToHeight(height(),Qt::SmoothTransformation); + overRight=over.copy(56,0,10,36).scaledToHeight(height(),Qt::SmoothTransformation); + } + } + QPainter paint; + paint.begin(this); + if(enabled && !isEnabled()) + { + setStyleSheet("border:none;color:#fab;"); + enabled=false; + } + if(!enabled && isEnabled()) + { + setStyleSheet("border:none;color:#afb;"); + enabled=true; + } + if(isDown() && isEnabled()) + { + paint.drawPixmap(0,0,backgroundPushedLeft.width(), backgroundPushedLeft.height(), backgroundPushedLeft); + paint.drawPixmap(backgroundPushedLeft.width(), 0, + width()-backgroundPushedLeft.width()-backgroundPushedRight.width(), backgroundPushedLeft.height(),backgroundPushedMiddle); + paint.drawPixmap(width()-backgroundPushedRight.width(),0, backgroundPushedRight.width(), backgroundPushedRight.height(),backgroundPushedRight); + } + else + { + paint.drawPixmap(0,0,backgroundLeft.width(), backgroundLeft.height(), backgroundLeft); + paint.drawPixmap(backgroundLeft.width(), 0, + width()-backgroundLeft.width()-backgroundRight.width(), backgroundLeft.height(),backgroundMiddle); + paint.drawPixmap(width()-backgroundRight.width(),0, backgroundRight.width(), backgroundRight.height(),backgroundRight); + } + if(over && isEnabled()) + { + paint.drawPixmap(0,0,overLeft.width(), overLeft.height(), overLeft); + paint.drawPixmap(overLeft.width(), 0, + width()-overLeft.width()-overRight.width(), overLeft.height(),overMiddle); + paint.drawPixmap(width()-overRight.width(),0, overRight.width(), overRight.height(),overRight); + } + QPushButton::paintEvent(event); +} + +void DarkButton::enterEvent(QEvent *e) +{ + over=true; + QWidget::enterEvent(e); + update(); +} +void DarkButton::leaveEvent(QEvent *e) +{ + over=false; + QWidget::leaveEvent(e); + update(); +} diff --git a/test/darkbutton/DarkButton.h b/test/darkbutton/DarkButton.h new file mode 100644 index 0000000..38dbb60 --- /dev/null +++ b/test/darkbutton/DarkButton.h @@ -0,0 +1,22 @@ +#ifndef DarkButton_H +#define DarkButton_H + +#include <QPushButton> + +class DarkButton : public QPushButton +{ +public: + DarkButton(QWidget *parent = nullptr); + void paintEvent(QPaintEvent *) override; +protected: + void enterEvent(QEvent *e) override; + void leaveEvent(QEvent *e) override; +private: + QPixmap backgroundLeft,backgroundMiddle,backgroundRight; + QPixmap backgroundPushedLeft,backgroundPushedMiddle,backgroundPushedRight; + QPixmap overLeft,overMiddle,overRight; + bool over; + bool enabled; +}; + +#endif // PROGRESSBARDARK_H diff --git a/test/darkbutton/MainWindow.cpp b/test/darkbutton/MainWindow.cpp new file mode 100644 index 0000000..78cda6a --- /dev/null +++ b/test/darkbutton/MainWindow.cpp @@ -0,0 +1,41 @@ +#include "MainWindow.h" +#include "ui_MainWindow.h" +#include <sys/stat.h> +#include <iostream> +#include <dirent.h> +#include <stdio.h> + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow), + darkButton(new DarkButton) +{ + ui->setupUi(this); + + darkButton->setText("toto"); + QIcon icon; + icon.addFile(QString::fromUtf8(":/cancelDarkD.png"), QSize(), QIcon::Normal, QIcon::Off); + icon.addFile(QString::fromUtf8(":/cancelDarkE.png"), QSize(), QIcon::Normal, QIcon::On); + darkButton->setIcon(icon); + darkButton->setCheckable(true); + + ui->verticalLayout->addWidget(darkButton); + connect(&timer,&QTimer::timeout,this,&MainWindow::create); + timer.start(1000); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::create() +{ + if(darkButton->isChecked()) + { + darkButton->setEnabled(!darkButton->isEnabled()); + darkButton->setChecked(false); + } + else + darkButton->setChecked(true); +} diff --git a/test/darkbutton/MainWindow.h b/test/darkbutton/MainWindow.h new file mode 100644 index 0000000..118257f --- /dev/null +++ b/test/darkbutton/MainWindow.h @@ -0,0 +1,26 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QTimer> +#include "DarkButton.h" + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + void create(); +private: + Ui::MainWindow *ui; + DarkButton * darkButton; + QTimer timer; +}; + +#endif // MAINWINDOW_H diff --git a/test/darkbutton/MainWindow.ui b/test/darkbutton/MainWindow.ui new file mode 100644 index 0000000..246d92c --- /dev/null +++ b/test/darkbutton/MainWindow.ui @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string>MainWindow</string> + </property> + <property name="styleSheet"> + <string notr="true">#MainWindow{background-color: qradialgradient(spread:pad, cx:0.5, cy:0.5, radius:0.5, fx:0.5, fy:0.5, stop:0 rgb(70, 70, 70), stop:1 rgb(40, 40, 40));}</string> + </property> + <widget class="QWidget" name="centralWidget"> + <layout class="QVBoxLayout" name="verticalLayout"/> + </widget> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> diff --git a/test/darkbutton/cancelDarkD.png b/test/darkbutton/cancelDarkD.png Binary files differnew file mode 100644 index 0000000..a2f4556 --- /dev/null +++ b/test/darkbutton/cancelDarkD.png diff --git a/test/darkbutton/cancelDarkE.png b/test/darkbutton/cancelDarkE.png Binary files differnew file mode 100644 index 0000000..1cda258 --- /dev/null +++ b/test/darkbutton/cancelDarkE.png diff --git a/test/darkbutton/darkButton.png b/test/darkbutton/darkButton.png Binary files differnew file mode 100644 index 0000000..561fc02 --- /dev/null +++ b/test/darkbutton/darkButton.png diff --git a/test/darkbutton/darkButtonOver.png b/test/darkbutton/darkButtonOver.png Binary files differnew file mode 100644 index 0000000..ea42018 --- /dev/null +++ b/test/darkbutton/darkButtonOver.png diff --git a/test/darkbutton/darkButtonPushed.png b/test/darkbutton/darkButtonPushed.png Binary files differnew file mode 100644 index 0000000..e2e63a5 --- /dev/null +++ b/test/darkbutton/darkButtonPushed.png diff --git a/test/darkbutton/darkbutton.pro b/test/darkbutton/darkbutton.pro new file mode 100644 index 0000000..fc31c76 --- /dev/null +++ b/test/darkbutton/darkbutton.pro @@ -0,0 +1,38 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2019-05-30T12:37:58 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = darkbutton +TEMPLATE = app + +# The following define makes your compiler emit warnings if you use +# any feature of Qt which has been marked as deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if you use deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +FORMS += \ + MainWindow.ui + +HEADERS += \ + MainWindow.h \ + DarkButton.h + +SOURCES += \ + main.cpp \ + MainWindow.cpp \ + DarkButton.cpp + +RESOURCES += \ + res.qrc diff --git a/test/darkbutton/main.cpp b/test/darkbutton/main.cpp new file mode 100644 index 0000000..af9caac --- /dev/null +++ b/test/darkbutton/main.cpp @@ -0,0 +1,11 @@ +#include "MainWindow.h" +#include <QApplication> + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/test/darkbutton/res.qrc b/test/darkbutton/res.qrc new file mode 100644 index 0000000..cd9341b --- /dev/null +++ b/test/darkbutton/res.qrc @@ -0,0 +1,9 @@ +<RCC> + <qresource prefix="/"> + <file>darkButton.png</file> + <file>darkButtonPushed.png</file> + <file>darkButtonOver.png</file> + <file>cancelDarkE.png</file> + <file>cancelDarkD.png</file> + </qresource> +</RCC> |