QString selectedIconPictureFileName)
: ImageButton(parent, normalIconPictureFileName, selectedIconPictureFileName)
{
- m_dragStartTimer = new QTimer(this);
- m_dragStartTimer->setSingleShot(true);
- connect(m_dragStartTimer, SIGNAL(timeout()),
- this, SLOT(timerExpired()));
+}
+
+void ZoomButton::mouseMoveEvent(QMouseEvent *event)
+{
+ if(this->rect().contains(event->pos())) {
+ m_eventPosition = mapToParent(event->pos());
+ emit eventPosition(m_eventPosition);
+ }
+ else {
+ ImageButton::mouseReleaseEvent(event);
+ emit releaseEvent();
+ }
}
void ZoomButton::mousePressEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- if(m_buttonMode != QIcon::Disabled) {
- QAbstractButton::mousePressEvent(event);
- setMode(QIcon::Selected);
- }
+ ImageButton::mousePressEvent(event);
+
m_eventPosition = mapToParent(event->pos());
- m_dragStartTimer->start(DRAG_INIT_TIME);
+ emit pressEvent();
+ emit eventPosition(m_eventPosition);
}
void ZoomButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- if(m_buttonMode != QIcon::Disabled) {
- QAbstractButton::mouseReleaseEvent(event);
- setMode(QIcon::Normal);
- }
+ ImageButton::mouseReleaseEvent(event);
- m_dragStartTimer->stop();
-}
-void ZoomButton::timerExpired()
-{
- qDebug() << __PRETTY_FUNCTION__;
+ emit releaseEvent();
- setMode(QIcon::Normal);
- emit startDragMode(true, m_eventPosition);
}
******************************************************************************/
protected:
/**
+ * @brief Event handler for mouse move events
+ *
+ * @param event Mouse event
+ */
+ void mouseMoveEvent(QMouseEvent *event);
+
+ /**
* @brief Event handler for mouse press events
*
* @param event Mouse event
void mouseReleaseEvent(QMouseEvent *event);
/*******************************************************************************
- * MEMBER FUNCTIONS AND SLOTS
- ******************************************************************************/
-private slots:
- /**
- * @brief Slot to emit signal to zoom button panel to start drag mode after timer timeout
- */
- void timerExpired();
-
-/*******************************************************************************
* SIGNALS
******************************************************************************/
signals:
- /**
- * @brief Signal for starting drag mode
- *
- * @param mode True to start drag mode
- * @param eventPosition Position of mousePressEvent mapped to parent
- */
- void startDragMode(bool mode, QPoint eventPosition);
+ void pressEvent();
+ void releaseEvent();
+ void eventPosition(QPoint m_eventPosition);
/*******************************************************************************
* DATA MEMBERS
ZoomButtonPanel::ZoomButtonPanel(QWidget *parent, int x, int y)
: QWidget(parent),
- m_zoomInButton(0),
- m_zoomOutButton(0),
m_isDraggable(false),
- m_panelLayout(this)
+ m_panelLayout(this),
+ m_zoomInButton(0),
+ m_zoomOutButton(0)
{
qDebug() << __PRETTY_FUNCTION__;
m_zoomInButton = new ZoomButton(this, ":/res/images/zoom_in.png");
m_zoomOutButton = new ZoomButton(this, ":/res/images/zoom_out.png");
+ m_zoomInButton->setObjectName("ZoomInButton");
+ m_zoomOutButton->setObjectName("ZoomOutButton");
m_panelLayout.setMargin(0);
m_panelLayout.setSpacing(0);
m_panelLayout.setVerticalSpacing(ZOOM_BUTTON_PANEL_BUTTON_SPACING);
m_eventBlocker->resize(size().width(),
m_zoomInButton->size().height() * 2 + ZOOM_BUTTON_PANEL_BUTTON_SPACING);
- connect(m_zoomInButton, SIGNAL(startDragMode(bool, QPoint)),
- this, SLOT(setDraggable(bool, QPoint)));
- connect(m_zoomOutButton, SIGNAL(startDragMode(bool, QPoint)),
- this, SLOT(setDraggable(bool, QPoint)));
-
m_dragStartTimer = new QTimer(this);
m_dragStartTimer->setSingleShot(true);
+ m_dragStartTimer->setInterval(DRAG_INIT_TIME);
+
+ connect(m_zoomInButton, SIGNAL(pressEvent()),
+ m_dragStartTimer, SLOT(start()));
+ connect(m_zoomInButton, SIGNAL(releaseEvent()),
+ m_dragStartTimer, SLOT(stop()));
+ connect(m_zoomOutButton, SIGNAL(pressEvent()),
+ m_dragStartTimer, SLOT(start()));
+ connect(m_zoomOutButton, SIGNAL(releaseEvent()),
+ m_dragStartTimer, SLOT(stop()));
+
+ connect(m_zoomInButton, SIGNAL(eventPosition(QPoint)),
+ this, SLOT(setDragPosition(QPoint)));
+ connect(m_zoomOutButton, SIGNAL(eventPosition(QPoint)),
+ this, SLOT(setDragPosition(QPoint)));
+
connect(m_dragStartTimer, SIGNAL(timeout()),
this, SLOT(timerExpired()));
+
}
void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
if(m_isDraggable) {
if (event->buttons() & Qt::LeftButton) {
QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
- if (newLocation.x() < SIDEBAR_WIDTH) {
+
+ if (newLocation.x() < SIDEBAR_WIDTH)
newLocation.rx() = SIDEBAR_WIDTH;
- }
- else if (newLocation.x() > m_screenSize.width()
- - m_eventBlocker->width()){
+ else if (newLocation.x() > m_screenSize.width() - m_eventBlocker->width())
newLocation.rx() = m_screenSize.width() - m_eventBlocker->width();
- }
- if (newLocation.y() < 0){
+
+ if (newLocation.y() < 0)
newLocation.ry() = 0;
- }
- else if (newLocation.y() > m_screenSize.height() - m_eventBlocker->height()) {
+ else if (newLocation.y() > m_screenSize.height() - m_eventBlocker->height())
newLocation.ry() = m_screenSize.height() - m_eventBlocker->height();
- }
+
move(newLocation);
event->accept();
}
}
+ else {
+ m_dragPosition = event->pos();
+ }
+
}
void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
m_dragPosition = event->pos();
event->accept();
}
- m_dragStartTimer->start(DRAG_INIT_TIME);
+ m_dragStartTimer->start();
}
void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
QSettings settings(DIRECTORY_NAME, FILE_NAME);
settings.setValue(ZOOMPANEL_POSITION, pos());
releaseMouse();
+ m_dragStartTimer->stop();
}
const ImageButton* ZoomButtonPanel::zoomInButton()
m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, false);
m_isDraggable = mode;
setAutoFillBackground(true);
+
m_zoomInMode = m_zoomInButton->mode();
m_zoomOutMode = m_zoomOutButton->mode();
+
m_zoomInButton->setMode(QIcon::Disabled);
m_zoomOutButton->setMode(QIcon::Disabled);
grabMouse();
m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
m_isDraggable = mode;
setAutoFillBackground(false);
- m_zoomInButton->setMode(m_zoomInMode);
- m_zoomOutButton->setMode(m_zoomOutMode);
+ if(m_zoomInMode == QIcon::Selected)
+ m_zoomInButton->setMode(QIcon::Normal);
+ else
+ m_zoomInButton->setMode(m_zoomInMode);
+ if(m_zoomOutMode == QIcon::Selected)
+ m_zoomOutButton->setMode(QIcon::Normal);
+ else
+ m_zoomOutButton->setMode(m_zoomOutMode);
releaseMouse();
+ m_zoomInButton->setDown(false);
+ m_zoomOutButton->setDown(false);
}
}
m_screenSize = size;
}
+void ZoomButtonPanel::setDragPosition(QPoint eventPosition)
+{
+ m_dragPosition = eventPosition;
+}
+
void ZoomButtonPanel::timerExpired()
{
setDraggable(true, m_dragPosition);