1
0
mirror of https://gitee.com/drabel/LibQQt.git synced 2025-01-04 10:18:44 +08:00
LibQQt/examples/exquisite/mainwindow.cpp

284 lines
10 KiB
C++
Raw Normal View History

#include "mainwindow.h"
#include "ui_mainwindow.h"
2017-10-20 23:29:42 +08:00
#include <QMouseEvent>
2017-10-20 20:52:19 +08:00
#include <QKeyEvent>
#include <qqtcore.h>
MainWindow::MainWindow(QWidget* parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
2017-10-20 20:52:19 +08:00
{
ui->setupUi(this);
value = 0;
curmaxValue = 80;
2017-10-20 20:52:19 +08:00
ui->hs0->setRange(0, 100);
2017-10-20 23:29:42 +08:00
2017-10-25 11:04:15 +08:00
ui->w01->setRange(0, 100);
ui->w01->setBackgroundColor(QColor(60, 80, 100));
ui->w01->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc);
ui->w01->setShowFree(true);
ui->w01->setShowSmallCircle(true);
ui->w0->setRange(0, 100);
ui->w0->setBackgroundColor(QColor(60, 80, 100));
ui->w0->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Polo);
ui->w1->setBackgroundColor(QColor(60, 80, 100));
ui->w1->setRange(0, 100);
ui->w1->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc_Polo);
ui->w2->setBackgroundColor(QColor(20, 40, 100));
ui->w2->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Wave);
2017-10-20 20:52:19 +08:00
ui->w2->setRange(0, 80);
2017-10-22 10:50:59 +08:00
ui->w2->setWaveDensity(2);
2017-10-25 11:04:15 +08:00
ui->w2->setWaveDirection(QQtCustomEffectProgressBar::WaveDirection_Left_Right);
2017-10-22 10:50:59 +08:00
ui->w2->setWaveHeight(2);
ui->w2->setWaveSpeed(6);
2017-10-25 11:04:15 +08:00
//ui->w2->setCircleType(QQtCustomEffectProgressBar::CircleType_Image);
2017-10-20 23:29:42 +08:00
//ui->w2->setCircleImage("./xxtest.png");
2017-10-25 11:04:15 +08:00
ui->w5->setRange(0, 100);
ui->w5->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Ellipse);
ui->w5->setBackgroundColor(QColor(36, 80, 100));
ui->w5->setRange(0, 100);
ui->w5->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc);
ui->w6->setRange(0, 100);
ui->w6->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Ellipse);
ui->w6->setBackgroundColor(QColor(36, 80, 100));
ui->w6->setRange(0, 100);
ui->w6->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Polo);
ui->w3->setRange(0, 100);
ui->w3->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Ellipse);
ui->w3->setBackgroundColor(QColor(36, 80, 100));
ui->w3->setRange(0, 100);
ui->w3->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc_Polo);
ui->w4->setRange(0, 80);
ui->w4->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Ellipse);
ui->w4->setBackgroundColor(QColor(20, 40, 100));
ui->w4->setWaveDensity(2);
ui->w4->setWaveDirection(QQtCustomEffectProgressBar::WaveDirection_Left_Right);
ui->w4->setWaveHeight(2);
ui->w4->setWaveSpeed(6);
ui->w4->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Wave);
ui->w40->setRange(0, 100);
ui->w40->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Rectangle);
ui->w40->setBackgroundColor(QColor(36, 80, 100));
ui->w40->setRange(0, 100);
ui->w40->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc);
ui->w41->setRange(0, 100);
ui->w41->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Rectangle);
ui->w41->setBackgroundColor(QColor(36, 80, 100));
ui->w41->setRange(0, 100);
ui->w41->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Polo);
ui->w42->setRange(0, 100);
ui->w42->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Rectangle);
ui->w42->setBackgroundColor(QColor(36, 80, 100));
ui->w42->setRange(0, 100);
ui->w42->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc_Polo);
ui->w43->setRange(0, 80);
ui->w43->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Rectangle);
ui->w43->setBackgroundColor(QColor(20, 40, 100));
ui->w43->setWaveDensity(2);
ui->w43->setWaveDirection(QQtCustomEffectProgressBar::WaveDirection_Left_Right);
ui->w43->setWaveHeight(2);
ui->w43->setWaveSpeed(6);
ui->w43->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Wave);
ui->w50->setRange(0, 100);
ui->w50->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Square);
ui->w50->setBackgroundColor(QColor(36, 80, 100));
ui->w50->setRange(0, 100);
ui->w50->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc);
ui->w51->setRange(0, 100);
ui->w51->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Square);
ui->w51->setBackgroundColor(QColor(36, 80, 100));
ui->w51->setRange(0, 100);
ui->w51->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Polo);
ui->w52->setRange(0, 100);
ui->w52->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Square);
ui->w52->setBackgroundColor(QColor(36, 80, 100));
ui->w52->setRange(0, 100);
ui->w52->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Arc_Polo);
ui->w53->setRange(0, 80);
ui->w53->setDesignStyle(QQtCustomEffectProgressBar::DesignStyle_Square);
ui->w53->setBackgroundColor(QColor(20, 40, 100));
ui->w53->setWaveDensity(2);
ui->w53->setWaveDirection(QQtCustomEffectProgressBar::WaveDirection_Left_Right);
ui->w53->setWaveHeight(2);
ui->w53->setWaveSpeed(6);
ui->w53->setPercentStyle(QQtCustomEffectProgressBar::PercentStyle_Wave);
2017-10-26 19:27:17 +08:00
//ui->w60->setRange(0, 100);
//ui->w60->setValue(100);
2017-10-25 11:04:15 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w01, SLOT(setValue(int)));
2017-10-20 20:52:19 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w0, SLOT(setValue(int)));
2017-10-25 11:04:15 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w1, SLOT(setValue(int)));
2017-10-20 20:52:19 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w2, SLOT(setValue(int)));
2017-10-25 11:04:15 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w3, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w4, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w5, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w6, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w40, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w41, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w42, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w43, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w50, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w51, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w52, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w53, SLOT(setValue(int)));
2017-10-26 19:27:17 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w60, SLOT(setValue(int)));
2017-10-25 11:04:15 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w7, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w8, SLOT(setValue(int)));
2017-10-22 10:50:59 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
ui->hs0->installEventFilter(this);
2017-10-20 20:52:19 +08:00
m_timer = new QTimer(this);
m_timer->setSingleShot(false);
2017-10-20 23:29:42 +08:00
m_timer_down = new QTimer(this);
m_timer_down->setSingleShot(false);
2017-10-20 20:52:19 +08:00
2017-10-20 23:29:42 +08:00
connect(m_timer_down, SIGNAL(timeout()), this, SLOT(setValueDown()));
2017-10-20 20:52:19 +08:00
connect(m_timer, SIGNAL(timeout()), this, SLOT(setValue()));
2017-10-20 23:29:42 +08:00
m_timer_down->start(10);
2017-10-20 20:52:19 +08:00
}
MainWindow::~MainWindow()
2017-10-20 20:52:19 +08:00
{
delete ui;
}
void MainWindow::setValue(int value)
2017-10-22 10:50:59 +08:00
{
this->value = value;
}
void MainWindow::setValue()
2017-10-20 20:52:19 +08:00
{
2017-10-22 10:50:59 +08:00
//pline() << value;
if (value > curmaxValue)
2017-10-20 23:29:42 +08:00
return;
2017-10-22 10:50:59 +08:00
if (value < curmaxValue)
2017-10-20 20:52:19 +08:00
value++;
2017-10-20 23:29:42 +08:00
2017-10-20 20:52:19 +08:00
ui->hs0->setValue(value);
}
void MainWindow::setValueDown()
2017-10-20 20:52:19 +08:00
{
2017-10-22 10:50:59 +08:00
if (value > 0)
2017-10-20 20:52:19 +08:00
value--;
ui->hs0->setValue(value);
}
void MainWindow::keyPressEvent(QKeyEvent* event)
2017-10-20 20:52:19 +08:00
{
2017-10-22 10:50:59 +08:00
//pline() << hex << event->key();
if (event->key() == Qt::Key_Up)
{
2017-10-20 23:29:42 +08:00
m_timer_down->stop();
2017-10-20 20:52:19 +08:00
m_timer->start(10);
event->accept();
}
QMainWindow::keyPressEvent(event);
2017-10-20 20:52:19 +08:00
}
void MainWindow::keyReleaseEvent(QKeyEvent* event)
2017-10-20 20:52:19 +08:00
{
2017-10-22 10:50:59 +08:00
if (event->key() == Qt::Key_Up)
{
2017-10-20 23:29:42 +08:00
m_timer_down->start(10);
2017-10-20 20:52:19 +08:00
m_timer->stop();
event->accept();
}
QMainWindow::keyReleaseEvent(event);
2017-10-20 20:52:19 +08:00
}
2017-10-20 23:29:42 +08:00
bool MainWindow::eventFilter(QObject* watched, QEvent* event)
2017-10-20 23:29:42 +08:00
{
2017-10-22 10:50:59 +08:00
if (event->type() != QEvent::Paint)
2017-10-22 01:13:39 +08:00
;//pline() << watched << hex << event->type();
2017-10-22 10:50:59 +08:00
if (watched == ui->hs0)
{
if (event->type() == QEvent::MouseButtonPress)
{
2017-10-20 23:29:42 +08:00
QMouseEvent* e = (QMouseEvent*)event;
//pline() << hex << e->button();
2017-10-22 10:50:59 +08:00
if (e->button() == Qt::LeftButton)
{
curmaxValue = ui->hs0->minimum() + (ui->hs0->maximum() - ui->hs0->minimum()) * e->x() / ui->hs0->width();
2017-10-20 23:29:42 +08:00
m_timer_down->stop();
m_timer->start(10);
// not necessary because of the bug later.
event->accept();
// bug:in theory this return is not necessary, after accept, parent won't handle this e continue;
// but, it handled. handled once, but child has no action any.
// then, use return ,don't goto parent, well to use.
return true;
}
}
2017-10-22 10:50:59 +08:00
if (event->type() == QEvent::MouseButtonRelease)
{
2017-10-20 23:29:42 +08:00
QMouseEvent* e = (QMouseEvent*)event;
//pline() << hex << e->button();
2017-10-22 10:50:59 +08:00
if (e->button() == Qt::LeftButton)
{
2017-10-20 23:29:42 +08:00
curmaxValue = 80;
m_timer->stop();
m_timer_down->start(10);
event->accept();
2017-10-22 01:13:39 +08:00
/*!
* linux
* after click slider, all key event come here....
* because, focus hasn't coming back,
* but on mac, focus has coming back.
!*/
ui->w0->setFocus();
return true;
2017-10-20 23:29:42 +08:00
}
}
2017-10-22 10:50:59 +08:00
if (event->type() == QEvent::MouseMove)
{
QMouseEvent* e = (QMouseEvent*)event;
//pline() << hex << e->button();
if (e->button() == Qt::NoButton)
{
curmaxValue = ui->hs0->minimum() + (ui->hs0->maximum() - ui->hs0->minimum()) * e->x() / ui->hs0->width();
value = curmaxValue - 1;
//pline() << curmaxValue;
event->accept();
return true;
}
}
/*fix the parent handled bug terminally*/
2017-10-22 10:50:59 +08:00
if (event->type() == QEvent::Paint)
{
return QMainWindow::eventFilter(watched, event);
}
//+ fix bug
return true;
2017-10-20 23:29:42 +08:00
}
return QMainWindow::eventFilter(watched, event);
2017-10-20 23:29:42 +08:00
}