This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Use RazorGridLayout in the DesktopSwitch plugin.

  • Loading branch information...
SokoloffA committed Mar 13, 2013
1 parent 155c73f commit 47b9f9cc3b07e663925c07b8c6bad62da573eecf
@@ -33,6 +33,7 @@
#include <QSignalMapper>
#include <razorqt/xfitman.h>
#include <razorqxt/qxtglobalshortcut.h>
+#include <razorqt/razorgridlayout.h>
#include <QHBoxLayout>
#include "desktopswitch.h"
@@ -51,7 +52,8 @@ DesktopSwitch::DesktopSwitch(const IRazorPanelPluginStartupInfo &startupInfo) :
m_buttons = new QButtonGroup(this);
connect ( m_pSignalMapper, SIGNAL(mapped(int)), this, SLOT(setDesktop(int)));
- mWidget.setLayout(new QHBoxLayout(&mWidget));
+ mLayout = new RazorGridLayout(&mWidget);
+ mWidget.setLayout(mLayout);
setup();
}
@@ -128,37 +130,39 @@ void DesktopSwitch::setDesktop(int desktop)
xfitMan().setActiveDesktop(desktop);
}
-void DesktopSwitch::wheelEvent(QWheelEvent* e)
+
+void DesktopSwitch::realign()
+{
+ mLayout->setEnabled(false);
+
+ if (panel()->isHorizontal())
+ {
+ mLayout->setRowCount(panel()->lineCount());
+ mLayout->setColumnCount(0);
+ }
+ else
+ {
+ mLayout->setColumnCount(panel()->lineCount());
+ mLayout->setRowCount(0);
+ }
+ mLayout->setEnabled(true);
+}
+
+DesktopSwitchWidget::DesktopSwitchWidget():
+ QFrame()
+{
+}
+
+void DesktopSwitchWidget::wheelEvent(QWheelEvent *e)
{
int max = xfitMan().getNumDesktop() - 1;
int delta = e->delta() < 0 ? 1 : -1;
int current = xfitMan().getActiveDesktop() + delta;
-
+
if (current > max)
current = 0;
else if (current < 0)
current = max;
xfitMan().setActiveDesktop(current);
}
-
-void DesktopSwitch::realign()
-{
- int max = 0;
- bool isHorizontal = panel()->isHorizontal();
- foreach (QAbstractButton *btn, m_buttons->buttons())
- {
- if (isHorizontal)
- max = qMax(max, btn->sizeHint().width());
- else
- max = qMax(max, btn->sizeHint().height());
- }
-
- foreach (QAbstractButton *btn, m_buttons->buttons())
- {
- if (isHorizontal)
- btn->setMinimumWidth(max);
- else
- btn->setMinimumHeight(max);
- }
-}
@@ -34,7 +34,17 @@
class QSignalMapper;
class QButtonGroup;
+class RazorGridLayout;
+class DesktopSwitchWidget: public QFrame
+{
+ Q_OBJECT
+public:
+ DesktopSwitchWidget();
+
+protected:
+ void wheelEvent(QWheelEvent* e);
+};
/**
* @brief Desktop switcher. A very simple one...
@@ -57,9 +67,9 @@ class DesktopSwitch : public QObject, public IRazorPanelPlugin
QSignalMapper* m_pSignalMapper;
int m_desktopCount;
QStringList m_desktopNames;
- QFrame mWidget;
+ DesktopSwitchWidget mWidget;
+ RazorGridLayout *mLayout;
- void wheelEvent(QWheelEvent* e);
void setup();
private slots:

0 comments on commit 47b9f9c

Please sign in to comment.