QtPickToolBar.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 83 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-02-27 17:31:45 +0100 (Fr, 27. Feb 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 //=============================================================================
00045 //
00046 //  CLASS QtPickToolbar
00047 //
00048 //=============================================================================
00049 
00050 
00051 //== GLOBAL DEFINITIONS=========================================================
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 //== INCLUDES =================================================================
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 //== IMPLEMENTATION ==========================================================
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* /*_option*/,
00135                                      QWidget* /*_widget*/ )
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   /* The QGraphicsProxyWidged does not sent the StatusTip messages to the main
00180      application window status bar. So we have to do it manually.
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 //=============================================================================

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .