QtPickToolBar.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #define BACKGROUND_RED 0xff
00054 #define BACKGROUND_GREEN 0xff
00055 #define BACKGROUND_BLUE 0xff
00056 #define BACKGROUND_ALPHA 0xcf
00057
00058 #define SLIDE_DURATION 1000
00059
00060
00061
00062
00063
00064 #include <OpenFlipper/common/GlobalOptions.hh>
00065
00066 #include <QPainter>
00067 #include <QGraphicsSceneMouseEvent>
00068 #include <QGraphicsScene>
00069 #include <QGraphicsView>
00070 #include <QDialog>
00071 #include <QVBoxLayout>
00072 #include <QToolBar>
00073 #include <QStatusBar>
00074 #include <QStatusTipEvent>
00075
00076 #include "QtPickToolbar.hh"
00077 #include "QtGraphicsButton.hh"
00078
00079
00080
00081
00082 QtPickToolbar::QtPickToolbar(QMainWindow *_core, QGraphicsItem *_parent) :
00083 QGraphicsProxyWidget(_parent),
00084 toolbar_(0),
00085 core_(_core)
00086 {
00087 setCacheMode (QGraphicsItem::DeviceCoordinateCache);
00088 setWindowFrameMargins (2, 2, 2, 2);
00089 setZValue (2.0);
00090
00091 hide ();
00092 }
00093
00094
00095
00096 void QtPickToolbar::attachToolbar (QToolBar *_t)
00097 {
00098 if (!_t)
00099 {
00100 detachToolbar ();
00101 return;
00102 }
00103
00104 if (_t == toolbar_)
00105 return;
00106
00107 toolbar_ = _t;
00108 toolbar_->setParent(0);
00109
00110 setWidget (toolbar_);
00111 setWindowFlags(Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
00112
00113 show ();
00114
00115 updateGeometry ();
00116 }
00117
00118
00119
00120 void QtPickToolbar::detachToolbar ()
00121 {
00122 if (toolbar_)
00123 {
00124 setWidget (0);
00125 hide ();
00126 toolbar_->setParent(0);
00127 toolbar_ = 0;
00128 }
00129 }
00130
00131
00132
00133 void QtPickToolbar::paintWindowFrame(QPainter *_painter,
00134 const QStyleOptionGraphicsItem* ,
00135 QWidget* )
00136 {
00137 int w = geometry().width();
00138 int h = geometry().height();
00139
00140 _painter->setRenderHint(QPainter::Antialiasing, true);
00141 _painter->setBrush(QBrush(QColor(BACKGROUND_RED,
00142 BACKGROUND_GREEN,
00143 BACKGROUND_BLUE,
00144 BACKGROUND_ALPHA)));
00145 _painter->setPen(QColor(BACKGROUND_RED / 4,
00146 BACKGROUND_GREEN / 4,
00147 BACKGROUND_BLUE / 4,
00148 BACKGROUND_ALPHA));
00149 _painter->drawRoundedRect(-2, -6, w + 4, h + 8, 4, 4);
00150
00151 _painter->setPen(Qt::SolidLine);
00152
00153
00154 }
00155
00156
00157
00158 Qt::WindowFrameSection QtPickToolbar::windowFrameSectionAt(const QPointF &_pos) const
00159 {
00160 return Qt::NoSection;
00161 }
00162
00163
00164
00165 void QtPickToolbar::updateGeometry ()
00166 {
00167 if (parentWidget () && widget ())
00168 {
00169 resize (qMin ((int)parentWidget ()->geometry ().width () - 20, widget ()->sizeHint ().width ()),
00170 widget ()->sizeHint ().height ());
00171 setPos ((parentWidget ()->geometry ().width () - geometry ().width ()) / 2, 0);
00172 }
00173 }
00174
00175
00176
00177 bool QtPickToolbar::eventFilter(QObject *_obj, QEvent *_event)
00178 {
00179
00180
00181
00182 if (_event->type () == QEvent::StatusTip)
00183 {
00184 if (core_->statusBar ())
00185 core_->statusBar ()->showMessage (dynamic_cast<QStatusTipEvent *>(_event)->tip());
00186
00187 return QGraphicsProxyWidget::eventFilter(_obj, _event);
00188 }
00189 else
00190 return QGraphicsProxyWidget::eventFilter(_obj, _event);
00191 }
00192
00193
00194