Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Michail Pishchagin mblsha authored
91 advwidget/advwidget.cpp
... ... @@ -0,0 +1,91 @@
  1 +#include "advwidget.h"
  2 +
  3 +#include <qapplication.h>
  4 +
  5 +#ifdef Q_OS_WIN
  6 +#include <windows.h>
  7 +#include <winuser.h>
  8 +#endif
  9 +
  10 +//----------------------------------------------------------------------------
  11 +// AdvancedWidget::Private
  12 +//----------------------------------------------------------------------------
  13 +
  14 +class AdvancedWidget::Private
  15 +{
  16 +public:
  17 + Private(AdvancedWidget *parent);
  18 +
  19 + AdvancedWidget *parent;
  20 + static int stickAt;
  21 +
  22 + void posChanging(int *x, int *y, int width, int height);
  23 +};
  24 +
  25 +int AdvancedWidget::Private::stickAt = 5;
  26 +
  27 +AdvancedWidget::Private::Private(AdvancedWidget *_parent)
  28 +{
  29 + parent = _parent;
  30 +}
  31 +
  32 +void AdvancedWidget::Private::posChanging(int *x, int *y, int width, int height)
  33 +{
  34 + // maybe cache this value?
  35 + QRect desktop = qApp->desktop()->availableGeometry(parent);
  36 +
  37 + if ( *x <= desktop.left() + stickAt &&
  38 + *x > -stickAt )
  39 + *x = desktop.left();
  40 +
  41 + if ( ((*x + width) > (desktop.right() - stickAt)) &&
  42 + ((*x + width) < (desktop.right() + stickAt)) )
  43 + *x = desktop.right() - width + 1;
  44 +
  45 + if ( (*y <= (desktop.top() + stickAt)) &&
  46 + (*y > -stickAt) )
  47 + *y = desktop.top();
  48 +
  49 + if ( (*y + height > desktop.bottom() - stickAt) &&
  50 + (*y + height < desktop.bottom() + stickAt) )
  51 + *y = desktop.bottom() - height + 1;
  52 +}
  53 +
  54 +//----------------------------------------------------------------------------
  55 +// AdvancedWidget
  56 +//----------------------------------------------------------------------------
  57 +
  58 +AdvancedWidget::AdvancedWidget(QWidget *parent, const char *name)
  59 +{
  60 + d = new Private(this);
  61 +}
  62 +
  63 +AdvancedWidget::~AdvancedWidget()
  64 +{
  65 + delete d;
  66 +}
  67 +
  68 +#ifdef Q_OS_WIN
  69 +bool AdvancedWidget::winEvent(MSG *msg)
  70 +{
  71 + if ( msg->message == WM_WINDOWPOSCHANGING ) {
  72 + WINDOWPOS *wpos = (WINDOWPOS *)msg->lParam;
  73 +
  74 + d->posChanging(&wpos->x, &wpos->y, &wpos->cx, &wpos->cy);
  75 +
  76 + return true;
  77 + }
  78 +
  79 + return false;
  80 +}
  81 +#endif
  82 +
  83 +int AdvancedWidget::stickAt()
  84 +{
  85 + return Private::stickAt;
  86 +}
  87 +
  88 +void AdvancedWidget::setStickAt(int val)
  89 +{
  90 + Private::stickAt = val;
  91 +}
26 advwidget/advwidget.h
... ... @@ -0,0 +1,26 @@
  1 +#ifndef ADVWIDGET_H
  2 +#define ADVWIDGET_H
  3 +
  4 +#include <qwidget.h>
  5 +
  6 +class AdvancedWidget : public QWidget
  7 +{
  8 + Q_OBJECT
  9 +public:
  10 + AdvancedWidget(QWidget *parent = 0, const char *name = 0);
  11 + ~AdvancedWidget();
  12 +
  13 + static int stickAt();
  14 + static void setStickAt(int val);
  15 +
  16 +protected:
  17 +#ifdef Q_OS_WIN
  18 + bool winEvent(MSG *msg);
  19 +#endif
  20 +
  21 +private:
  22 + class Private;
  23 + Private *d;
  24 +};
  25 +
  26 +#endif
15 advwidget/test.cpp
... ... @@ -0,0 +1,15 @@
  1 +#include <qapplication.h>
  2 +
  3 +#include "advwidget.h"
  4 +
  5 +int main(int argc, char *argv[])
  6 +{
  7 + QApplication app(argc, argv);
  8 +
  9 + AdvancedWidget *widget = new AdvancedWidget();
  10 + app.setMainWidget(widget);
  11 +
  12 + widget->show();
  13 +
  14 + return app.exec();
  15 +}
9 advwidget/test.pro
... ... @@ -0,0 +1,9 @@
  1 +TEMPLATE = app
  2 +CONFIG += qt
  3 +
  4 +SOURCES += \
  5 + advwidget.cpp \
  6 + test.cpp
  7 +
  8 +HEADERS += \
  9 + advwidget.h

0 comments on commit 0d05a87

Please sign in to comment.
Something went wrong with that request. Please try again.