this, SIGNAL(findFriend(QPointF)));
connect(m_mapView, SIGNAL(viewResized(QSize)),
- m_zoomButtonPanel, SLOT(screenResized(QSize)));
-
- connect(m_mapView, SIGNAL(viewResized(QSize)),
m_friendsListPanel, SLOT(screenResized(QSize)));
connect(this, SIGNAL(locationItemClicked(QList<QString>)),
{
qDebug() << __PRETTY_FUNCTION__;
- m_zoomButtonPanel = new ZoomButtonPanel(this, ZOOM_BUTTON_PANEL_POSITION_X,
- ZOOM_BUTTON_PANEL_POSITION_Y);
+ m_zoomButtonPanel = new ZoomButtonPanel(this);
connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
this, SIGNAL(zoomIn()));
connect(this, SIGNAL(minZoomLevelReached()),
m_zoomButtonPanel, SLOT(disableZoomOutButton()));
- QSettings settings(DIRECTORY_NAME, FILE_NAME);
- m_zoomButtonPanel->move(settings.value(ZOOMPANEL_POSITION,
- QPoint(ZOOM_BUTTON_PANEL_POSITION_X,
- ZOOM_BUTTON_PANEL_POSITION_Y)).toPoint());
+ connect(m_mapView, SIGNAL(viewResized(QSize)),
+ m_zoomButtonPanel, SLOT(screenResized(QSize)));
}
void MainWindow::createMenus()
enum Side {LEFT, RIGHT}; ///< Enumerator for panel sideness
-const int DRAG_INIT_TIME = 1000; ///< How long buttons must be pressed to start drag mode
+const int DRAG_INIT_TIME = 1000; ///< How long buttons must be pressed to start drag mode
+const int FORCE_RELEASE_TIME = 10000; ///< How long mouse can be grabbed
-const int SIDEBAR_WIDTH = 23; ///< Width of the sidebar
-const int SIDEBAR_HEIGHT = 424; ///< Height of the sidebar
+const int SIDEBAR_WIDTH = 23; ///< Width of the sidebar
+const int SIDEBAR_HEIGHT = 424; ///< Height of the sidebar
-const int SLIDINGBAR_WIDTH = 24; ///< Width of the slidingbar
-const int SLIDINGBAR_HEIGHT = 424; ///< Height of the slidingbar
+const int SLIDINGBAR_WIDTH = 24; ///< Width of the slidingbar
+const int SLIDINGBAR_HEIGHT = 424; ///< Height of the slidingbar
-const int PANEL_PEEK_AMOUNT = 25; ///< Amount of pixels shown when panel is closed
+const int PANEL_PEEK_AMOUNT = 25; ///< Amount of pixels shown when panel is closed
-const int FRIENDPANEL_WIDTH = 430; ///< Width of the friends list panel
+const int FRIENDPANEL_WIDTH = 430; ///< Width of the friends list panel
const int FRIENDPANEL_HEIGHT = DEFAULT_SCREEN_HEIGHT; ///< Height of the friends list panel
-const int USERPANEL_WIDTH = 300; ///< Width of the user panel
+const int USERPANEL_WIDTH = 300; ///< Width of the user panel
const int USERPANEL_HEIGHT = DEFAULT_SCREEN_HEIGHT; ///< Height of the user panetl
const int MARGIN_CORRECTION = 1; ///< Amount of correction to make panels touch the window borders
const int MARGIN_CORRECTION2 = 2; ///< Amount of correction to make panels touch the window borders
-const int PANEL_TOP_Y = 0; ///< Y coordinate for top of both panels
-const int TOP_CORNER_X = 0; ///< X coordinate for top left corner
+const int PANEL_TOP_Y = 0; ///< Y coordinate for top of both panels
+const int TOP_CORNER_X = 0; ///< X coordinate for top left corner
const int FRIENDPANEL_CLOSED_X =
DEFAULT_SCREEN_WIDTH - PANEL_PEEK_AMOUNT
- - SLIDINGBAR_WIDTH; ///< X location of the friend list panel when closed
+ - SLIDINGBAR_WIDTH; ///< X location of the friend list panel when closed
const int FRIENDPANEL_OPENED_X =
DEFAULT_SCREEN_WIDTH - FRIENDPANEL_WIDTH
- - SLIDINGBAR_WIDTH; ///< X location of the friend list panel when opened
+ - SLIDINGBAR_WIDTH; ///< X location of the friend list panel when opened
const int USERPANEL_CLOSED_X =
2 - USERPANEL_WIDTH + PANEL_PEEK_AMOUNT; ///< X location of the user panel when closed
-const int USERPANEL_OPENED_X = 0; ///< X location of the user panel when opened
+const int USERPANEL_OPENED_X = 0; ///< X location of the user panel when opened
const int ZOOM_BUTTON_PANEL_POSITION_X = 10
const int ZOOM_BUTTON_PANEL_POSITION_Y = 10; ///< Vertical position of zoom panel
const int ZOOM_BUTTON_PANEL_BUTTON_SPACING = 4; ///< Size of a zoom button spacing
+const QString ZOOMPANEL_POSITION = "Zoom_Panel_Position";
+
#endif // PANELCOMMON_H
#include "zoombutton.h"
#include "common.h"
-ZoomButtonPanel::ZoomButtonPanel(QWidget *parent, int x, int y)
+ZoomButtonPanel::ZoomButtonPanel(QWidget *parent)
: QWidget(parent),
m_isDraggable(false),
m_panelLayout(this),
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_panelLayout.addWidget(m_zoomInButton, 0, 0);
m_panelLayout.addWidget(m_zoomOutButton, 1, 0);
- move(x, y);
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ move(settings.value(ZOOMPANEL_POSITION,
+ QPoint(ZOOM_BUTTON_PANEL_POSITION_X,
+ ZOOM_BUTTON_PANEL_POSITION_Y)).toPoint());
QPalette pal = palette();
pal.setColor(QPalette::Background, QColor(0, 0, 0, 128));
setPalette(pal);
- m_eventBlocker = new QWidget(this);
- m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
- m_eventBlocker->resize(size().width(),
- m_zoomInButton->size().height() * 2 + ZOOM_BUTTON_PANEL_BUTTON_SPACING);
-
m_dragStartTimer = new QTimer(this);
m_dragStartTimer->setSingleShot(true);
m_dragStartTimer->setInterval(DRAG_INIT_TIME);
- connect(m_zoomInButton, SIGNAL(pressEvent()),
+ m_forceReleaseTimer = new QTimer(this);
+ m_forceReleaseTimer->setSingleShot(true);
+ m_forceReleaseTimer->setInterval(FORCE_RELEASE_TIME);
+
+ connect(m_zoomInButton, SIGNAL(pressed()),
m_dragStartTimer, SLOT(start()));
- connect(m_zoomInButton, SIGNAL(releaseEvent()),
+ connect(m_zoomInButton, SIGNAL(released()),
m_dragStartTimer, SLOT(stop()));
- connect(m_zoomOutButton, SIGNAL(pressEvent()),
+ connect(m_zoomOutButton, SIGNAL(pressed()),
m_dragStartTimer, SLOT(start()));
- connect(m_zoomOutButton, SIGNAL(releaseEvent()),
+ connect(m_zoomOutButton, SIGNAL(released()),
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()));
-
+ connect(m_forceReleaseTimer, SIGNAL(timeout()),
+ this, SLOT(forceMouseRelease()));
}
void ZoomButtonPanel::mouseMoveEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
- if(this->rect().contains(event->pos())) {
- if(m_isDraggable) {
- if (event->buttons() & Qt::LeftButton) {
- QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
-
- if (newLocation.x() < SIDEBAR_WIDTH)
- newLocation.rx() = SIDEBAR_WIDTH;
- else if (newLocation.x() > m_screenSize.width() - m_eventBlocker->width())
- newLocation.rx() = m_screenSize.width() - m_eventBlocker->width();
-
- if (newLocation.y() < 0)
- newLocation.ry() = 0;
- 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();
+ if(m_isDraggable) {
+ if (event->buttons() & Qt::LeftButton) {
+ QPoint newLocation = mapToParent(event->pos()) - m_dragPosition;
+
+ if (newLocation.x() < SIDEBAR_WIDTH)
+ newLocation.rx() = SIDEBAR_WIDTH;
+ else if (newLocation.x() > m_screenSize.width() - width() - SIDEBAR_WIDTH)
+ newLocation.rx() = m_screenSize.width() - width() - SIDEBAR_WIDTH;
+
+ if (newLocation.y() < 0)
+ newLocation.ry() = 0;
+ else if (newLocation.y() > m_screenSize.height() - height())
+ newLocation.ry() = m_screenSize.height() - height();
+
+ move(newLocation);
}
- }
- else {
- if(m_isDraggable)
- mouseReleaseEvent(event);
- else
+ } else {
+ if(!rect().contains(event->pos()))
m_dragStartTimer->stop();
}
-
+ QWidget::mouseMoveEvent(event);
}
void ZoomButtonPanel::mousePressEvent(QMouseEvent *event)
if (event->button() == Qt::LeftButton) {
m_dragPosition = event->pos();
- event->accept();
}
m_dragStartTimer->start();
+ QWidget::mousePressEvent(event);
}
void ZoomButtonPanel::mouseReleaseEvent(QMouseEvent *event)
settings.setValue(ZOOMPANEL_POSITION, pos());
releaseMouse();
m_dragStartTimer->stop();
+ m_zoomInButton->setDown(false);
+ m_zoomOutButton->setDown(false);
}
+ QWidget::mouseReleaseEvent(event);
}
const ZoomButton* ZoomButtonPanel::zoomInButton()
{
qDebug() << __PRETTY_FUNCTION__;
- if(mode == true) {
- m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, false);
- m_isDraggable = mode;
+ m_isDraggable = mode;
+
+ if(mode) {
setAutoFillBackground(true);
m_zoomInMode = m_zoomInButton->mode();
m_zoomInButton->setMode(QIcon::Disabled);
m_zoomOutButton->setMode(QIcon::Disabled);
grabMouse();
+ m_forceReleaseTimer->start();
m_dragPosition = eventPosition;
- }
- else {
- m_eventBlocker->setAttribute(Qt::WA_TransparentForMouseEvents, true);
- m_isDraggable = mode;
+ } else {
setAutoFillBackground(false);
if(m_zoomInMode == QIcon::Selected)
m_zoomInButton->setMode(QIcon::Normal);
else
m_zoomOutButton->setMode(m_zoomOutMode);
releaseMouse();
+ m_forceReleaseTimer->stop();
m_zoomInButton->setDown(false);
m_zoomOutButton->setDown(false);
}
}
-void ZoomButtonPanel::screenResized(const QSize &size)
+void ZoomButtonPanel::screenResized(const QSize &newSize)
{
qDebug() << __PRETTY_FUNCTION__;
-
- m_screenSize = size;
+ m_screenSize = newSize;
+
+ QPoint resizedPosition = pos();
+ if(resizedPosition.x() > (newSize.width() - rect().width()) - SIDEBAR_WIDTH)
+ resizedPosition.rx() = newSize.width() - rect().width() - SIDEBAR_WIDTH;
+ else if (resizedPosition.x() < SIDEBAR_WIDTH)
+ resizedPosition.rx() = SIDEBAR_WIDTH;
+ if(resizedPosition.y() > (newSize.height() - rect().height()))
+ resizedPosition.ry() = newSize.height() - rect().height();
+ else if (resizedPosition.y() < 0)
+ resizedPosition.ry() = 0;
+ move(resizedPosition);
}
-void ZoomButtonPanel::setDragPosition(QPoint eventPosition)
-{
+void ZoomButtonPanel::forceMouseRelease() {
qDebug() << __PRETTY_FUNCTION__;
- m_dragPosition = eventPosition;
+ releaseMouse();
+ setDraggable(false);
}
void ZoomButtonPanel::timerExpired()
{
qDebug() << __PRETTY_FUNCTION__;
+ if(m_zoomInButton->isDown())
+ m_dragPosition = m_zoomInButton->eventPosition();
+ if(m_zoomOutButton->isDown())
+ m_dragPosition = m_zoomOutButton->eventPosition();
setDraggable(true, m_dragPosition);
}