Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial version

git-svn-id: file:///home/justin/tmp/tmp/svn/neatstuff/trunk@31 972056c0-ec0e-4c9f-ad5b-9eb1d9b6bad5
  • Loading branch information...
commit 0d05a876f27cb3e615e8136337f5f71cc91c9cdf 1 parent db4c192
@mblsha mblsha authored
View
91 advwidget/advwidget.cpp
@@ -0,0 +1,91 @@
+#include "advwidget.h"
+
+#include <qapplication.h>
+
+#ifdef Q_OS_WIN
+#include <windows.h>
+#include <winuser.h>
+#endif
+
+//----------------------------------------------------------------------------
+// AdvancedWidget::Private
+//----------------------------------------------------------------------------
+
+class AdvancedWidget::Private
+{
+public:
+ Private(AdvancedWidget *parent);
+
+ AdvancedWidget *parent;
+ static int stickAt;
+
+ void posChanging(int *x, int *y, int width, int height);
+};
+
+int AdvancedWidget::Private::stickAt = 5;
+
+AdvancedWidget::Private::Private(AdvancedWidget *_parent)
+{
+ parent = _parent;
+}
+
+void AdvancedWidget::Private::posChanging(int *x, int *y, int width, int height)
+{
+ // maybe cache this value?
+ QRect desktop = qApp->desktop()->availableGeometry(parent);
+
+ if ( *x <= desktop.left() + stickAt &&
+ *x > -stickAt )
+ *x = desktop.left();
+
+ if ( ((*x + width) > (desktop.right() - stickAt)) &&
+ ((*x + width) < (desktop.right() + stickAt)) )
+ *x = desktop.right() - width + 1;
+
+ if ( (*y <= (desktop.top() + stickAt)) &&
+ (*y > -stickAt) )
+ *y = desktop.top();
+
+ if ( (*y + height > desktop.bottom() - stickAt) &&
+ (*y + height < desktop.bottom() + stickAt) )
+ *y = desktop.bottom() - height + 1;
+}
+
+//----------------------------------------------------------------------------
+// AdvancedWidget
+//----------------------------------------------------------------------------
+
+AdvancedWidget::AdvancedWidget(QWidget *parent, const char *name)
+{
+ d = new Private(this);
+}
+
+AdvancedWidget::~AdvancedWidget()
+{
+ delete d;
+}
+
+#ifdef Q_OS_WIN
+bool AdvancedWidget::winEvent(MSG *msg)
+{
+ if ( msg->message == WM_WINDOWPOSCHANGING ) {
+ WINDOWPOS *wpos = (WINDOWPOS *)msg->lParam;
+
+ d->posChanging(&wpos->x, &wpos->y, &wpos->cx, &wpos->cy);
+
+ return true;
+ }
+
+ return false;
+}
+#endif
+
+int AdvancedWidget::stickAt()
+{
+ return Private::stickAt;
+}
+
+void AdvancedWidget::setStickAt(int val)
+{
+ Private::stickAt = val;
+}
View
26 advwidget/advwidget.h
@@ -0,0 +1,26 @@
+#ifndef ADVWIDGET_H
+#define ADVWIDGET_H
+
+#include <qwidget.h>
+
+class AdvancedWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ AdvancedWidget(QWidget *parent = 0, const char *name = 0);
+ ~AdvancedWidget();
+
+ static int stickAt();
+ static void setStickAt(int val);
+
+protected:
+#ifdef Q_OS_WIN
+ bool winEvent(MSG *msg);
+#endif
+
+private:
+ class Private;
+ Private *d;
+};
+
+#endif
View
15 advwidget/test.cpp
@@ -0,0 +1,15 @@
+#include <qapplication.h>
+
+#include "advwidget.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ AdvancedWidget *widget = new AdvancedWidget();
+ app.setMainWidget(widget);
+
+ widget->show();
+
+ return app.exec();
+}
View
9 advwidget/test.pro
@@ -0,0 +1,9 @@
+TEMPLATE = app
+CONFIG += qt
+
+SOURCES += \
+ advwidget.cpp \
+ test.cpp
+
+HEADERS += \
+ advwidget.h
Please sign in to comment.
Something went wrong with that request. Please try again.