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

172 lines
4.7 KiB
C++
Raw Normal View History

2017-10-20 20:52:19 +08:00
#include "qqtexquisiteform.h"
#include "ui_qqtexquisiteform.h"
2017-10-20 23:29:42 +08:00
#include <QMouseEvent>
2017-10-20 20:52:19 +08:00
#include <QKeyEvent>
#include <qqtcore.h>
2017-10-22 10:50:59 +08:00
QQtExquisiteForm::QQtExquisiteForm(QWidget* parent) :
2017-10-20 20:52:19 +08:00
QDialog(parent),
ui(new Ui::QQtExquisiteForm)
{
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-20 20:52:19 +08:00
ui->w0->setMinValue(0);
ui->w0->setMaxValue(80);
2017-10-20 23:29:42 +08:00
ui->w2->setCircleColor(QColor(20, 40, 100));
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-24 09:49:44 +08:00
ui->w2->setWaveDirection(QQtComplexProgressBar::WaveDirection_Left_Right);
2017-10-22 10:50:59 +08:00
ui->w2->setWaveHeight(2);
ui->w2->setWaveSpeed(6);
2017-10-24 09:49:44 +08:00
ui->w2->setPercentStyle(QQtComplexProgressBar::PercentStyle_Wave);
//ui->w2->setCircleType(QQtComplexProgressBar::CircleType_Image);
2017-10-20 23:29:42 +08:00
//ui->w2->setCircleImage("./xxtest.png");
2017-10-20 20:52:19 +08:00
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w0, SLOT(setValue(int)));
connect(ui->hs0, SIGNAL(valueChanged(int)), ui->w2, 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
}
QQtExquisiteForm::~QQtExquisiteForm()
{
delete ui;
}
2017-10-22 10:50:59 +08:00
void QQtExquisiteForm::setValue(int value)
{
this->value = value;
}
2017-10-20 20:52:19 +08:00
void QQtExquisiteForm::setValue()
{
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 QQtExquisiteForm::setValueDown()
{
2017-10-22 10:50:59 +08:00
if (value > 0)
2017-10-20 20:52:19 +08:00
value--;
ui->hs0->setValue(value);
}
2017-10-22 10:50:59 +08:00
void QQtExquisiteForm::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();
}
QDialog::keyPressEvent(event);
}
2017-10-22 10:50:59 +08:00
void QQtExquisiteForm::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();
}
QDialog::keyReleaseEvent(event);
}
2017-10-20 23:29:42 +08:00
2017-10-22 10:50:59 +08:00
bool QQtExquisiteForm::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 QDialog::eventFilter(watched, event);
}
//+ fix bug
return true;
2017-10-20 23:29:42 +08:00
}
return QDialog::eventFilter(watched, event);
}