m_friendListHeaderWidget->setLayout(filterLayout);
m_friendListHeaderWidget->setAutoFillBackground(true);
- m_routeButton = new ImageButton(this, ":res/images/route_to_friend.png",
- ":res/images/route_to_friend_s.png");
+ m_routeButton = new ImageButton(":res/images/route_to_friend.png",
+ ":res/images/route_to_friend_s.png", "", this);
m_routeButton->setDisabled(true);
QPalette labelPalette = m_friendListHeaderWidget->palette();
m_friendListHeaderWidget->setPalette(labelPalette);
m_friendListHeaderWidget->hide();
m_friendListLabel = new QLabel(this);
- m_clearFilterButton = new ImageButton(this, ":res/images/filtered.png",
- ":res/images/filtered_s.png");
+ m_clearFilterButton = new ImageButton(":res/images/filtered.png",
+ ":res/images/filtered_s.png", "", this);
m_clearFilterButton->setCheckable(true);
this, SLOT(topmostWindowChanged(bool)));
// CONTEXT BUTTONS
- m_contextButtonList.append(m_routeButton);
- m_contextButtonList.append(m_clearFilterButton);
+ m_contextButtonLayout->addWidget(m_routeButton, 0, 0);
+ m_contextButtonLayout->addWidget(m_clearFilterButton, 1, 0);
}
void FriendListPanel::anyPanelClosed()
USA.
*/
-#include <QSize>
#include <QDebug>
-#include <QPixmap>
+#include <QMouseEvent>
#include <QPainter>
#include "imagebutton.h"
-ImageButton::ImageButton(QWidget *parent, QString normalIconPictureFileName,
- QString selectedIconPictureFileName)
- : QPushButton(parent),
- m_buttonMode(QIcon::Normal)
+ImageButton::ImageButton(const QString &normalIconPictureFileName,
+ const QString &selectedIconPictureFileName,
+ const QString &disabledIconPictureFileName, QWidget *parent)
+ : QPushButton(parent)
{
qDebug() << __PRETTY_FUNCTION__;
if(!selectedIconPictureFileName.isEmpty())
icon.addFile(selectedIconPictureFileName, buttonSize, QIcon::Selected);
+ // If there is a picture for disabled state, use it instead of a simple color change
+ if(!disabledIconPictureFileName.isEmpty())
+ icon.addFile(disabledIconPictureFileName, buttonSize, QIcon::Disabled);
+
initButton(buttonSize, icon);
}
}
initButton(buttonSize, icon);
}
-void ImageButton::mousePressEvent(QMouseEvent *event)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if(m_buttonMode != QIcon::Disabled) {
- QPushButton::mousePressEvent(event);
- setMode(QIcon::Selected);
- } else {
- setDown(true);
- emit pressed();
- }
-}
-
-void ImageButton::mouseReleaseEvent(QMouseEvent *event)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if(m_buttonMode != QIcon::Disabled) {
- QPushButton::mouseReleaseEvent(event);
- setMode(QIcon::Normal);
- } else {
- setDown(false);
- emit released();
- }
-}
-
void ImageButton::paintEvent(QPaintEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
Q_UNUSED(event);
QPainter painter(this);
- icon().paint(&painter, this->rect(), NULL, m_buttonMode);
-}
-void ImageButton::setMode(QIcon::Mode mode)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_buttonMode = mode;
- update();
-}
-
-QIcon::Mode ImageButton::mode()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- return m_buttonMode;
+ if (isEnabled()) {
+ if (isChecked())
+ icon().paint(&painter, rect(), NULL, QIcon::Selected);
+ else if (isDown())
+ icon().paint(&painter, rect(), NULL, QIcon::Selected);
+ else
+ icon().paint(&painter, rect(), NULL, QIcon::Normal);
+ } else {
+ icon().paint(&painter, rect(), NULL, QIcon::Disabled);
+ }
}
void ImageButton::initButton(const QSize &size, const QIcon &icon)
#ifndef IMAGEBUTTON_H
#define IMAGEBUTTON_H
-#include <QIcon>
-#include <QString>
-#include <QWidget>
#include <QPushButton>
-#include <QMouseEvent>
-#include <QPaintEvent>
/**
* @brief A simple class for icon button
/**
* @brief Constructor
*
- * @param parent Parent
* @param normalIconPictureFileName Normal state icon image file name
* @param selectedIconPictureFileName Selected state icon image file name (optional)
+ * @param disabledIconPictureFileName Disabled state icon image file name (optional)
+ * @param parent Parent
*/
- ImageButton(QWidget *parent = 0, QString normalIconPictureFileName = "",
- QString selectedIconPictureFileName = "");
+ ImageButton(const QString &normalIconPictureFileName = QString(),
+ const QString &selectedIconPictureFileName = QString(),
+ const QString &disabledIconPictureFileName = QString(), QWidget *parent = 0);
/*******************************************************************************
* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
******************************************************************************/
protected:
/**
- * @brief Event handler for mouse press events
- *
- * @param event Mouse event
- */
- void mousePressEvent(QMouseEvent *event);
-
- /**
- * @brief Event handler for mouse release events
- *
- * @param event Mouse event
- */
- void mouseReleaseEvent(QMouseEvent *event);
-
- /**
* @brief Event handler for paint events
*
* Paints the button and its icon
*/
void setButtonIcon(const QPixmap &image);
- /**
- * @brief Sets the button icon mode
- *
- * @param mode Button icon mode
- */
- void setMode(QIcon::Mode mode);
-
- /**
- * @brief Returns the current button icon mode
- *
- * @return Button icon mode
- */
- QIcon::Mode mode();
-
private:
/**
* @brief Initializes the button by setting graphics and alpha mask
* @param icon Image icon
*/
void initButton(const QSize &size, const QIcon &icon);
-
-/*******************************************************************************
- * DATA MEMBERS
- ******************************************************************************/
-protected:
- QIcon::Mode m_buttonMode; ///< Button mode (Normal, Selected etc...)
};
#endif // IMAGEBUTTON_H
return m_eventPosition;
}
-void IndicatorButton::mouseMoveEvent(QMouseEvent *event)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- QToolButton::mouseMoveEvent(event);
-
- event->ignore();
-}
-
void IndicatorButton::mousePressEvent(QMouseEvent *event)
{
qDebug() << __PRETTY_FUNCTION__;
******************************************************************************/
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
connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
- connect(m_routingPanel,
- SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
- this,
- SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
+ connect(m_routingPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+ this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
this, SIGNAL(routeTo(const GeoCoordinate&)));
: QWidget(parent)
{
qDebug() << __PRETTY_FUNCTION__;
+
+ const int CONTEXT_BUTTON_MARGIN_LEFT = 2;
+ const int CONTEXT_BUTTON_MARGIN_TOP = 10;
+ const int CONTEXT_BUTTON_MARGIN_RIGHT = 0;
+ const int CONTEXT_BUTTON_MARGIN_BOTTOM = 0;
+ const int CONTEXT_BUTTON_SPACING = 0;
+
+ m_contextButtons = new QWidget;
+
+ m_contextButtonLayout = new QGridLayout;
+ m_contextButtonLayout->setContentsMargins(CONTEXT_BUTTON_MARGIN_LEFT,
+ CONTEXT_BUTTON_MARGIN_TOP,
+ CONTEXT_BUTTON_MARGIN_RIGHT,
+ CONTEXT_BUTTON_MARGIN_BOTTOM);
+ m_contextButtonLayout->setSpacing(CONTEXT_BUTTON_SPACING);
+
+ m_contextButtons->setLayout(m_contextButtonLayout);
}
-const QList<ImageButton *>& PanelBase::contextButtons() const
+QWidget* PanelBase::contextButtons() const
{
qDebug() << __PRETTY_FUNCTION__;
- return m_contextButtonList;
+ return m_contextButtons;
}
#ifndef PANELBASE_H
#define PANELBASE_H
+#include <QGridLayout>
#include <QWidget>
class ImageButton;
******************************************************************************/
public:
/**
- * @brief Get list of context buttons
+ * @brief Getter for the context buttons
*
- * @returns Reference to list of context buttons
+ * @returns Pointer to context buttons widget
*/
- const QList<ImageButton *>& contextButtons() const;
+ QWidget* contextButtons() const;
/*******************************************************************************
* SIGNALS
* DATA MEMBERS
******************************************************************************/
protected:
- QList<ImageButton *> m_contextButtonList; ///< List of context buttons
+ QGridLayout *m_contextButtonLayout; ///< Layout for context buttons
+
+private:
+ QWidget *m_contextButtons; ///< Widget for context buttons
};
#endif // PANELBASE_H
#include <QDebug>
#include <QPainter>
-#include "imagebutton.h"
-
#include "panelcontextbuttonbar.h"
const int CONTEXT_BUTTON_BAR_WIDTH = 78;
PanelContextButtonBar::PanelContextButtonBar(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent),
+ m_contextButtons(0)
{
qDebug() << __PRETTY_FUNCTION__;
}
-void PanelContextButtonBar::setContextButtons(const QList<ImageButton *> &contextButtonList)
+void PanelContextButtonBar::setContextButtons(QWidget *contextButtons)
{
qDebug() << __PRETTY_FUNCTION__;
- const int CONTEXT_BUTTON_HEIGHT = 74;
- const int CONTEXT_BUTTON_MARGIN_LEFT = 2;
- const int CONTEXT_BUTTON_MARGIN_TOP = 10;
-
// Hide previous buttons (if any)
- for (int i = 0; i < m_contextButtonList.size(); i ++) {
- m_contextButtonList.at(i)->setParent(0);
- }
+ if (m_contextButtons)
+ m_contextButtons->setParent(0);
- m_contextButtonList = contextButtonList;
+ m_contextButtons = contextButtons;
- for (int i = 0; i < m_contextButtonList.size(); i ++) {
- m_contextButtonList.at(i)->setParent(this);
- m_contextButtonList.at(i)->setVisible(true);
- m_contextButtonList.at(i)->move(CONTEXT_BUTTON_MARGIN_LEFT,
- CONTEXT_BUTTON_MARGIN_TOP + (CONTEXT_BUTTON_HEIGHT * i));
- }
+ m_contextButtons->setParent(this);
+ m_contextButtons->setVisible(true);
- setFixedHeight(CONTEXT_BUTTON_MARGIN_TOP + (CONTEXT_BUTTON_HEIGHT * contextButtonList.size()));
+ setFixedHeight(m_contextButtons->height());
emit positionChangeRequested();
}
#include <QWidget>
-class ImageButton;
-
class PanelContextButtonBar : public QWidget
{
Q_OBJECT
/**
* @brief Sets the context buttons to the context button bar
*
- * @param contextButtonList List of context buttons
+ * @param contextButtons Pointer to context buttons
*/
- void setContextButtons(const QList<ImageButton *> &contextButtonList);
+ void setContextButtons(QWidget *contextButtons);
/*******************************************************************************
* SIGNALS
* DATA MEMBERS
******************************************************************************/
private:
- QList<ImageButton *> m_contextButtonList;
+ QPixmap m_barTile; ///< Pixmap for button bar
+ QPixmap m_barTop; ///< Pixmap for button bar top
- QPixmap m_barTile; ///< Pixmap for button bar
- QPixmap m_barTop; ///< Pixmap for button bar top
+ QRect m_barRect; ///< Rect for the button bar
- QRect m_barRect; ///< Rect for the button bar
+ QWidget *m_contextButtons; ///< Widget for context buttons
};
#endif // PANELCONTEXTBUTTONBAR_H
listViewLayout->setContentsMargins(PANEL_MARGIN_LEFT, PANEL_MARGIN_TOP,
PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
- ImageButton *searchLocationButton = new ImageButton(0, ":/res/images/search.png",
- ":/res/images/search_s.png");
+ ImageButton *searchLocationButton = new ImageButton(":/res/images/search.png",
+ ":/res/images/search_s.png",
+ "", this);
- m_contextButtonList.append(searchLocationButton);
+ m_contextButtonLayout->addWidget(searchLocationButton, 0, 0);
- m_routeButton = new ImageButton(this, ":res/images/route_to_location.png",
- ":res/images/route_to_location_s.png");
+ m_routeButton = new ImageButton(":res/images/route_to_location.png",
+ ":res/images/route_to_location_s.png", "", this);
m_routeButton->setDisabled(true);
- m_routeButton->hide();
m_locationListHeaderWidget = new QWidget();
m_locationListHeaderWidget->setLayout(headerLayout);
listViewLayout->addWidget(m_locationListView);
listViewLayout->addWidget(m_routeWaypointListView);
- routingLayout->addWidget(m_routeButton);
routingLayout->addWidget(m_locationListHeaderWidget);
routingLayout->addLayout(listViewLayout);
this, SIGNAL(requestSearchLocation()));
// CONTEXT BUTTONS
- m_contextButtonList.append(m_routeButton);
+ m_contextButtonLayout->addWidget(m_routeButton, 1, 0);
}
void RoutingPanel::clearListsSelections()
{
qDebug() << __PRETTY_FUNCTION__;
- m_routeButton->show();
-
m_locationListHeaderWidget->show();
m_locationListLabel->setText(tr("Search results: %1").arg(locations.count()));
{
qDebug() << __PRETTY_FUNCTION__;
- m_routeButton->hide();
-
m_locationListHeaderWidget->hide();
m_locationListView->hide();
m_routeWaypointListView->show();
#include <QFormLayout>
#include <QLabel>
+#include <QMouseEvent>
#include <QPainter>
#include <QSettings>
#include <QVBoxLayout>
connect(this, SIGNAL(clearUpdateLocationDialogData()),
m_userInfo, SLOT(clearUpdateLocationDialogData()));
- ImageButton *updateFriendsButton = new ImageButton(this, ":/res/images/refresh.png",
- ":/res/images/refresh_s.png");
- ImageButton *updateStatusMessageButton = new ImageButton(this, ":/res/images/send_position.png",
- ":/res/images/send_position_s.png");
-
- m_contextButtonList.append(updateFriendsButton);
- m_contextButtonList.append(updateStatusMessageButton);
+ ImageButton *updateFriendsButton = new ImageButton(":/res/images/refresh.png",
+ ":/res/images/refresh_s.png",
+ "", this);
+ ImageButton *updateStatusMessageButton = new ImageButton(":/res/images/send_position.png",
+ ":/res/images/send_position_s.png",
+ "", this);
+
+ m_contextButtonLayout->addWidget(updateFriendsButton, 0, 0);
+ m_contextButtonLayout->addWidget(updateStatusMessageButton, 1, 0);
connect(updateFriendsButton, SIGNAL(clicked()),
this, SIGNAL(refreshUserData()));
*/
#include <QDebug>
-#include <QTimer>
+#include <QMouseEvent>
#include "zoombutton.h"
#include "panelcommon.h"
-ZoomButton::ZoomButton(QWidget *parent, QString normalIconPictureFileName,
- QString selectedIconPictureFileName)
- : ImageButton(parent, normalIconPictureFileName, selectedIconPictureFileName)
+ZoomButton::ZoomButton(const QString &iconPictureFileName, QWidget *parent)
+ : ImageButton(iconPictureFileName, "", "", parent)
{
qDebug() << __PRETTY_FUNCTION__;
}
{
qDebug() << __PRETTY_FUNCTION__;
- ImageButton::mousePressEvent(event);
-
m_eventPosition = mapToParent(event->pos());
+
+ ImageButton::mousePressEvent(event);
}
const QPoint& ZoomButton::eventPosition()
#ifndef ZOOMBUTTON_H
#define ZOOMBUTTON_H
-class QTimer;
-
#include "imagebutton.h"
/**
/**
* @brief Constructor
*
+ * @param iconPictureFileName Icon image file name
* @param parent Parent
- * @param normalIconPictureFileName Normal state Icon image file name
- * @param selectedIconPictureFileName Selected state Icon image file name (optional)
*/
- ZoomButton(QWidget *parent = 0, QString normalIconPictureFileName = QString(),
- QString selectedIconPictureFileName = QString());
+ ZoomButton(const QString &iconPictureFileName = QString(), QWidget *parent = 0);
/*******************************************************************************
* BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
*/
#include <QDebug>
+#include <QMouseEvent>
#include <QPainter>
#include <QSettings>
{
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 = new ZoomButton(":/res/images/zoom_in.png", this);
+ m_zoomOutButton = new ZoomButton(":/res/images/zoom_out.png", this);
m_panelLayout.setMargin(0);
m_panelLayout.setSpacing(0);
}
}
-const ZoomButton* ZoomButtonPanel::zoomInButton()
+const ZoomButton* ZoomButtonPanel::zoomInButton() const
{
qDebug() << __PRETTY_FUNCTION__;
return m_zoomInButton;
}
-const ZoomButton* ZoomButtonPanel::zoomOutButton()
+const ZoomButton* ZoomButtonPanel::zoomOutButton() const
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- m_zoomInButton->setMode(QIcon::Disabled);
+ m_zoomInButton->setEnabled(false);
}
void ZoomButtonPanel::disableZoomOutButton()
{
qDebug() << __PRETTY_FUNCTION__;
- m_zoomOutButton->setMode(QIcon::Disabled);
+ m_zoomOutButton->setEnabled(false);
}
void ZoomButtonPanel::resetButtons()
{
qDebug() << __PRETTY_FUNCTION__;
- m_zoomInButton->setMode(QIcon::Normal);
- m_zoomOutButton->setMode(QIcon::Normal);
+ m_zoomInButton->setEnabled(true);
+ m_zoomOutButton->setEnabled(true);
}
void ZoomButtonPanel::setDraggable(bool mode, QPoint eventPosition)
if(mode) {
emit draggingModeTriggered();
- m_zoomInMode = m_zoomInButton->mode();
- m_zoomOutMode = m_zoomOutButton->mode();
- m_zoomInButton->setMode(QIcon::Disabled);
- m_zoomOutButton->setMode(QIcon::Disabled);
+ m_zoomInMode = m_zoomInButton->isEnabled();
+ m_zoomOutMode = m_zoomOutButton->isEnabled();
+
+ m_zoomInButton->setEnabled(false);
+ m_zoomOutButton->setEnabled(false);
grabMouse();
m_forceReleaseTimer->start();
m_dragPosition = eventPosition;
} else {
- 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);
+ m_zoomInButton->setEnabled(m_zoomInMode);
+ m_zoomOutButton->setEnabled(m_zoomOutMode);
releaseMouse();
m_forceReleaseTimer->stop();
+
m_zoomInButton->setDown(false);
m_zoomOutButton->setDown(false);
}
*
* @return Pointer to the zoomInButton
*/
- const ZoomButton* zoomInButton();
+ const ZoomButton* zoomInButton() const;
/**
* @brief Getter for the zoom out button
*
* @return Pointer to the zoomOutButton
*/
- const ZoomButton* zoomOutButton();
+ const ZoomButton* zoomOutButton() const;
public slots:
/**
******************************************************************************/
private:
bool m_isDraggable; ///< Boolean for tracking the draggability state
+ bool m_zoomInMode; ///< Boolean for storing zoom in button mode before dragging
+ bool m_zoomOutMode; ///< Boolean for storing zoom out button mode before dragging
QGridLayout m_panelLayout; ///< Panel layout
QPoint m_dragPosition; ///< Location from where the widget is grabbed
- QIcon::Mode m_zoomInMode; ///< Store for zoom in button mode before dragging
- QIcon::Mode m_zoomOutMode; ///< Store for zoom out button mode before dragging
-
QSize m_screenSize; ///< Store for the screen size
QTimer *m_dragStartTimer; ///< Timer to init draggability of the zoom panel
testtabbedpanel.cpp \
../../../src/ui/tabbedpanel.cpp \
../../../src/ui/panelbar.cpp \
+ ../../../src/ui/panelbase.cpp \
../../../src/ui/panelcontentstack.cpp \
+ ../../../src/ui/panelcontextbuttonbar.cpp \
../../../src/ui/paneltab.cpp \
../../../src/ui/paneltabbar.cpp
HEADERS += \
../../../src/ui/tabbedpanel.h \
../../../src/ui/panelbar.h \
+ ../../../src/ui/panelbase.h \
../../../src/ui/panelcontentstack.h \
+ ../../../src/ui/panelcontextbuttonbar.h \
../../../src/ui/paneltab.h \
../../../src/ui/paneltabbar.h \
../../../src/ui/panelcommon.h
#include <QtTest/QtTest>
#include <QtCore>
-#include <QWidget>
+#include "ui/panelbase.h"
#include "ui/tabbedpanel.h"
class TestTabbedPanel : public QObject
void TestTabbedPanel::testPanelToggling()
{
- TabbedPanel *testPanel = new TabbedPanel();
+ TabbedPanel *testTabbedPanel = new TabbedPanel;
- QWidget *testWidget = new QWidget();
- testPanel->addTab(testWidget, QIcon(":/res/images/user_info.png"));
+ PanelBase *testPanel = new PanelBase;
+ testTabbedPanel->addTab(testPanel, QIcon(":/res/images/user_info.png"));
QSignalSpy closedSpy(testPanel, SIGNAL(panelClosed()));
QSignalSpy openedSpy(testPanel, SIGNAL(panelOpened()));
QCOMPARE(toggleSpy.count(), 0);
// Try to close the panel. As the panel is closed, no signals should be sent.
- testPanel->closePanel();
+ testTabbedPanel->closePanel();
QTest::qWait(1);
QCOMPARE(closedSpy.count(), 0);
QCOMPARE(openedSpy.count(), 0);
QCOMPARE(toggleSpy.count(), 0);
// Now try to open the panel, only toggleState and panelOpened signals should be sent
- testPanel->showPanel(testWidget);
+ testTabbedPanel->showPanel(testPanel);
QTest::qWait(1);
QCOMPARE(closedSpy.count(), 0);
QCOMPARE(openedSpy.count(), 0);
QCOMPARE(toggleSpy.count(), 1);
// Now try to open the panel again. As the panel is already open, no signals should not be sent.
- testPanel->showPanel(testWidget);
+ testTabbedPanel->showPanel(testPanel);
QTest::qWait(1);
QCOMPARE(closedSpy.count(), 0);
QCOMPARE(openedSpy.count(), 1);
QCOMPARE(toggleSpy.count(), 1);
//Now try to close the panel, only toggleState and panelClosed signals should be sent
- testPanel->closePanel();
+ testTabbedPanel->closePanel();
QTest::qWait(1);
QCOMPARE(closedSpy.count(), 0);
QCOMPARE(openedSpy.count(), 1);
QCOMPARE(openedSpy.count(), 1);
QCOMPARE(toggleSpy.count(), 2);
- delete testWidget;
delete testPanel;
+ delete testTabbedPanel;
}
QTEST_MAIN(TestTabbedPanel)