|
|
@ -54,6 +54,10 @@ DelegateButton::DelegateButton(const QString & fileName, QGraphicsItem* pDelegat |
|
|
|
: QGraphicsSvgItem(fileName, parent) |
|
|
|
: QGraphicsSvgItem(fileName, parent) |
|
|
|
, mDelegated(pDelegated) |
|
|
|
, mDelegated(pDelegated) |
|
|
|
, mIsTransparentToMouseEvent(false) |
|
|
|
, mIsTransparentToMouseEvent(false) |
|
|
|
|
|
|
|
, mIsPressed(false) |
|
|
|
|
|
|
|
, mProgressTimerId(-1) |
|
|
|
|
|
|
|
, mPressProgres(0) |
|
|
|
|
|
|
|
, mShowProgressIndicator(false) |
|
|
|
, mButtonAlignmentSection(section) |
|
|
|
, mButtonAlignmentSection(section) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setAcceptedMouseButtons(Qt::LeftButton); |
|
|
|
setAcceptedMouseButtons(Qt::LeftButton); |
|
|
@ -71,9 +75,14 @@ void DelegateButton::setFileName(const QString & fileName) |
|
|
|
QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this)); |
|
|
|
QGraphicsSvgItem::setSharedRenderer(new QSvgRenderer (fileName, this)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (mShowProgressIndicator) { |
|
|
|
|
|
|
|
QTimer::singleShot(300, this, SLOT(startShowProgress())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mIsPressed = true; |
|
|
|
|
|
|
|
|
|
|
|
// make sure delegate is selected, to avoid control being hidden
|
|
|
|
// make sure delegate is selected, to avoid control being hidden
|
|
|
|
mPressedTime = QTime::currentTime(); |
|
|
|
mPressedTime = QTime::currentTime(); |
|
|
|
|
|
|
|
|
|
|
@ -82,15 +91,59 @@ void DelegateButton::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
|
|
|
|
|
|
|
|
void DelegateButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
void DelegateButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (mShowProgressIndicator && mProgressTimerId != -1) { |
|
|
|
|
|
|
|
killTimer(mProgressTimerId); |
|
|
|
|
|
|
|
mPressProgres = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mIsPressed = false; |
|
|
|
int timeto = qAbs(QTime::currentTime().msecsTo(mPressedTime)); |
|
|
|
int timeto = qAbs(QTime::currentTime().msecsTo(mPressedTime)); |
|
|
|
|
|
|
|
|
|
|
|
if (timeto < UBSettings::longClickInterval) { |
|
|
|
if (timeto < UBSettings::longClickInterval) { |
|
|
|
emit clicked(); |
|
|
|
emit clicked(); |
|
|
|
|
|
|
|
qDebug() << "clicked"; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
emit longClicked(); |
|
|
|
emit longClicked(); |
|
|
|
|
|
|
|
qDebug() << "longClicked"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
event->setAccepted(!mIsTransparentToMouseEvent); |
|
|
|
event->setAccepted(!mIsTransparentToMouseEvent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DelegateButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QGraphicsSvgItem::paint(painter, option, widget); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mIsPressed && mShowProgressIndicator) { |
|
|
|
|
|
|
|
QPen pen; |
|
|
|
|
|
|
|
pen.setBrush(Qt::darkRed); |
|
|
|
|
|
|
|
pen.setWidth(3); |
|
|
|
|
|
|
|
painter->save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter->setPen(pen); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int spanAngle = qMin(mPressProgres, UBSettings::longClickInterval) * 360 / UBSettings::longClickInterval; |
|
|
|
|
|
|
|
painter->drawArc(option->rect.adjusted(pen.width(), pen.width(), -pen.width(), -pen.width()), 16 * 90, -16 * spanAngle); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
painter->restore(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DelegateButton::timerEvent(QTimerEvent *event) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (event->timerId() == mProgressTimerId) { |
|
|
|
|
|
|
|
mPressProgres = qAbs(QTime::currentTime().msecsTo(mPressedTime)); |
|
|
|
|
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DelegateButton::startShowProgress() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (mIsPressed) { |
|
|
|
|
|
|
|
mProgressTimerId = startTimer(37); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate, bool useToolBar) |
|
|
|
UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObject * parent, bool respectRatio, bool canRotate, bool useToolBar) |
|
|
@ -139,11 +192,13 @@ void UBGraphicsItemDelegate::init() |
|
|
|
mButtons << mMenuButton; |
|
|
|
mButtons << mMenuButton; |
|
|
|
|
|
|
|
|
|
|
|
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); |
|
|
|
mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", mDelegated, mFrame, Qt::BottomLeftSection); |
|
|
|
|
|
|
|
mZOrderUpButton->setShowProgressIndicator(true); |
|
|
|
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); |
|
|
|
connect(mZOrderUpButton, SIGNAL(clicked()), this, SLOT(increaseZLevelUp())); |
|
|
|
connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); |
|
|
|
connect(mZOrderUpButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelTop())); |
|
|
|
mButtons << mZOrderUpButton; |
|
|
|
mButtons << mZOrderUpButton; |
|
|
|
|
|
|
|
|
|
|
|
mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); |
|
|
|
mZOrderDownButton = new DelegateButton(":/images/z_layer_down.svg", mDelegated, mFrame, Qt::BottomLeftSection); |
|
|
|
|
|
|
|
mZOrderDownButton->setShowProgressIndicator(true); |
|
|
|
connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); |
|
|
|
connect(mZOrderDownButton, SIGNAL(clicked()), this, SLOT(increaseZLevelDown())); |
|
|
|
connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); |
|
|
|
connect(mZOrderDownButton, SIGNAL(longClicked()), this, SLOT(increaseZlevelBottom())); |
|
|
|
mButtons << mZOrderDownButton; |
|
|
|
mButtons << mZOrderDownButton; |
|
|
|