CoreWidget.hh 15.7 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
//=============================================================================
//
//                               OpenFlipper
//        Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
//                           www.openflipper.org
//
//-----------------------------------------------------------------------------
//
//                                License
//
//  OpenFlipper is free software: you can redistribute it and/or modify
//  it under the terms of the GNU Lesser General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  OpenFlipper is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public License
//  along with OpenFlipper.  If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
//   $Revision$
//   $Author$
//   $Date$
//
//=============================================================================



//=============================================================================
//
//  CLASS CoreWidget
//
//=============================================================================

/**
 * \file CoreWidget.hh
 * This File contains the header of the frameworks main widget
*/

#ifndef COREWIDGET_HH
#define COREWIDGET_HH


//== INCLUDES =================================================================

#include "OpenFlipper/common/Types.hh"
#include <OpenFlipper/BasePlugin/ContextMenuInterface.hh>
#include <OpenFlipper/BasePlugin/LoggingInterface.hh>
#include <OpenFlipper/BasePlugin/MenuInterface.hh>
#include <OpenFlipper/BasePlugin/ViewInterface.hh>
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>


#include <ACG/QtWidgets/QtExaminerViewer.hh>

// QT INCLUDES
#include <QMainWindow>
#include <QStackedWidget>
#include <QTextEdit>
#include <QToolBar>
#include <QStatusBar>

#include <QDockWidget>

Jan Möbius's avatar
Jan Möbius committed
70
#include <OpenFlipper/widgets/aboutWidget/aboutWidget.hh>
71
#include <OpenFlipper/widgets/loggerWidget/loggerWidget.hh>
72
#include <OpenFlipper/widgets/optionsWidget/optionsWidget.hh>
Jan Möbius's avatar
 
Jan Möbius committed
73 74
#include <OpenFlipper/widgets/helpBrowser/helpWidget.hh>

Dirk Wilden's avatar
Dirk Wilden committed
75
#include <OpenFlipper/Core/PluginInfo.hh>
Jan Möbius's avatar
 
Jan Möbius committed
76

Jan Möbius's avatar
Jan Möbius committed
77

Jan Möbius's avatar
 
Jan Möbius committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
struct ViewMode{
      QString name;
      bool custom; //is the mode defined by the user?
      QStringList visibleWidgets;
};

class StackWidgetInfo {
  public:
    StackWidgetInfo(bool _editable,QString _name,QWidget* _widget);

    bool editable;
    QString name;
    QWidget* widget;
};

/** Info struct containing information about custom context menus
 */
struct MenuInfo {
  /// The context Menu
  QMenu*          menu;

  /// Type of objects for which the context Menu should be visible
  DataType        contextType;

  /// Position of the context Menu inside the main widgets context Menu
  ContextMenuType position;
};

/** Core Widget of the Application
 */
class CoreWidget : public QMainWindow
{
  Q_OBJECT

public:

  /// constructor
Dirk Wilden's avatar
Dirk Wilden committed
115
  CoreWidget( QVector<ViewMode*>& _viewModes, std::vector<PluginInfo>& _plugins );
Jan Möbius's avatar
 
Jan Möbius committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138

  /// destructor
  ~CoreWidget();

  signals:
    void clearAll();
    void loadMenu();
    void addEmptyObjectMenu();
    void saveMenu();
    void saveToMenu();
    void loadIniMenu();
    void saveIniMenu();
    void recentOpen(QAction*);
    void exit();

    void loadPlugin();
    void unloadPlugin();

  private slots:

    /// Called on applications close
    void closeEvent ( QCloseEvent * event );

Dirk Wilden's avatar
Dirk Wilden committed
139 140 141 142 143 144 145 146 147 148 149
   //===========================================================================
  /** @name Logger
  * @{ */
  //===========================================================================

  signals :
      void log(Logtype _type, QString _message);
      void log(QString _message);

   /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
   //===========================================================================
  /** @name Keys
  * @{ */
  //===========================================================================

  protected :

    //! Handle key events
    virtual void keyPressEvent (QKeyEvent* _e);
    virtual void keyReleaseEvent(QKeyEvent* _e);

  signals :
   /// When this Signal is emitted when a Keyevent Event occures
   void PluginKeyEvent(QKeyEvent* );

   /// When this Signal is emitted when a key release event event occures
   void PluginKeyReleaseEvent(QKeyEvent* );

Dirk Wilden's avatar
Dirk Wilden committed
168
   /// internal signal to register CoreWidget keys
Dirk Wilden's avatar
Dirk Wilden committed
169 170
   void registerKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description,
                    bool _multiUse = false);
Dirk Wilden's avatar
Dirk Wilden committed
171 172

  private:
Dirk Wilden's avatar
Dirk Wilden committed
173 174
    ///typedefs
    typedef std::multimap<  std::pair< int, Qt::KeyboardModifiers >  ,  std::pair< QObject*, int > > KeyMap;
Dirk Wilden's avatar
Dirk Wilden committed
175

Dirk Wilden's avatar
Dirk Wilden committed
176 177 178 179 180 181 182 183 184 185 186
    typedef std::multimap< std::pair< QObject*, int >, std::pair< int, Qt::KeyboardModifiers > > InverseKeyMap;

    typedef std::pair< KeyMap::iterator, KeyMap::iterator > KeyRange;

    /// Handle core key events
    void coreKeyPressEvent  (QKeyEvent* _e);
    void coreKeyReleaseEvent(QKeyEvent* _e);

    KeyBinding getKeyBinding(QObject* _plugin, int _keyIndex );

    ///vector of keys registered to the core
Dirk Wilden's avatar
Dirk Wilden committed
187 188
    std::vector<KeyBinding> coreKeys_;

Dirk Wilden's avatar
Dirk Wilden committed
189 190 191 192 193 194
    ///mapping of all keys to registered keys and the corresponding plugins
    KeyMap keys_;

    ///mapping of all registered keys and the corresponding plugins to currently assigned keys
    InverseKeyMap invKeys_;

Dirk Wilden's avatar
Dirk Wilden committed
195
  private slots:
Dirk Wilden's avatar
Dirk Wilden committed
196 197 198 199 200
    void slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description,
                         bool _multiUse = false);

  public slots:
    void slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID);
Dirk Wilden's avatar
Dirk Wilden committed
201

Jan Möbius's avatar
 
Jan Möbius committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
   /** @} */

  //===========================================================================
  /** @name GUI creation
  * @{ */
  //===========================================================================

  public:

  /// Setup the main menubar
  void setupMenuBar();

  /// Add a recent file and update menu
  void addRecent(QString _filename, DataType _type);

  /// Update the recent files menu
  void updateRecent();

  /** @} */
Jan Möbius's avatar
Jan Möbius committed
221

Jan Möbius's avatar
 
Jan Möbius committed
222 223 224 225
  //===========================================================================
  /** @name GUI Controls
  * @{ */
  //===========================================================================
Jan Möbius's avatar
Jan Möbius committed
226

Jan Möbius's avatar
 
Jan Möbius committed
227 228 229
  public :
    /// Set application to Fullscreen and back
    void toggleFullscreen();
Jan Möbius's avatar
Jan Möbius committed
230

231 232 233
    /// Enable or disable fullscreen mode
    void setFullscreen(bool _state );

Jan Möbius's avatar
 
Jan Möbius committed
234 235
    /// Hide or show logging area
    void toggleLogger();
236 237

    /// Change visibility of the logger
238
    void showLogger(bool _state);
Jan Möbius's avatar
Jan Möbius committed
239

Jan Möbius's avatar
 
Jan Möbius committed
240 241
    /// Hide or show toolbox area
    void toggleToolbox();
Jan Möbius's avatar
Jan Möbius committed
242

243 244 245
    /// Show or hide toolbox
    void showToolbox( bool _state );

Jan Möbius's avatar
 
Jan Möbius committed
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  /** @} */

  //===========================================================================
    /** @name Tool Widgets / View Modes
    * @{ */
  //===========================================================================

    private:
      /// a List of all widgets in the toolbar
      QVector<QWidget*> toolWidgets_;

    public:
      /// List of currently available viewModes
      QVector<ViewMode*>& viewModes_;

      ///DockWidget and Button for changing viewMode via dialog
      QDockWidget* dockViewMode_;

    private:

      QPushButton* viewModeButton_;

      /// Submenu holding all ViewMode actions
      QMenu* viewModeMenu_;

      /// Group for all menu items
      QActionGroup* viewGroup_;

    public:
      /// Tab all DockWidgets which belong to ToolWidgets together
276
      void tabDockWidgets(QVector< QDockWidget* > _widgets);
Jan Möbius's avatar
 
Jan Möbius committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321

    public slots:

      /// init ViewModes that were loaded via ini-file
      void initViewModes(  );

      /// Add a new ViewMode (non-userdefined viewMode)
      void slotAddViewMode(QString _mode, QStringList _usedWidgets);

      /// Add a new ViewMode (_custom == userdefined viewMode)
      void slotAddViewMode(QString _mode, bool _custom, QStringList _usedWidgets);

      /// Slot for Changing visible toolWidgets
      void slotChangeView(QString _mode, QStringList _toolWidgets);

    private slots:
      /// Remove viewMode
      void slotRemoveViewMode(QString _name);

      /// Slot for setting ViewMode from Menu
      void slotSetViewMode( QAction* action);


      /// Show a dialog in which the viewMode can be changed
      void slotViewModeDialog();

      /// Slot is called when the visibility of a toolWidget changes
      void slotVisibilityChanged ( bool visible );

      /// Set the view Mode to the given Mode
    public slots :
      void setViewMode( QString _mode );

   /** @} */



  //===========================================================================
    /** @name Basic Gui Elements
    * @{ */
  //===========================================================================

  public :

    /// Examiner Widget
Jan Möbius's avatar
Jan Möbius committed
322 323 324 325
    std::vector< ACG::QtWidgets::QtExaminerViewer* >  examiner_widgets_;

    /// temporary pointer pointing to first element of above vector for porting to multi view mode
    ACG::QtWidgets::QtExaminerViewer* examiner_widget_;
Jan Möbius's avatar
 
Jan Möbius committed
326 327 328

    ///Spliter between toplevel objects and the textedit at the bottom
    QSplitter* splitter_;
Jan Möbius's avatar
Jan Möbius committed
329

Jan Möbius's avatar
 
Jan Möbius committed
330
    /// Textedit at the bottom for log messages
331
    LoggerWidget* logWidget_;
Jan Möbius's avatar
Jan Möbius committed
332

Jan Möbius's avatar
 
Jan Möbius committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
    /// Size of the logging window ( defaults to 240 )
    int originalLoggerSize_;

    /// QMenu containing the recently opened files
    QMenu* recentFilesMenu_;

    /// Plugins Menu
    QMenu* pluginsMenu_;

    /// Help Menu
    QMenu* helpMenu_;

  /** @} */

  private slots:
   /** Display a log message in the Mainwidget
    * @param _type Type of Message (OUT,WARN,ERR)
    * @param _message The message to be displayed
    */
   void slotLog(Logtype _type, QString _message);

  //===========================================================================
    /** @name Menubar controls
      * @{ */
  //===========================================================================
  private slots :

    void slotAddMenu( QMenu* _menu , MenuType _type );

  private:

    /// File Menu
    QMenu *fileMenu_;

    /// View Menu
    QMenu *viewMenu_;

    /// First entry after all relevant parts of the File Menu
    QAction* fileMenuEnd_;

  /** @} */
Jan Möbius's avatar
Jan Möbius committed
374

Jan Möbius's avatar
 
Jan Möbius committed
375 376 377 378
  //===========================================================================
    /** @name ToolBar controls
      * @{ */
  //===========================================================================
Jan Möbius's avatar
Jan Möbius committed
379
  private:
Jan Möbius's avatar
 
Jan Möbius committed
380
    QToolBar* viewerToolbar_;
Dirk Wilden's avatar
Dirk Wilden committed
381 382

    int toolbarCount_;
Jan Möbius's avatar
Jan Möbius committed
383

Jan Möbius's avatar
 
Jan Möbius committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
  /** @} */

  //===========================================================================
    /** @name Context Menu
      * @{ */
  //===========================================================================
  signals :
    // tells the plugins to update their context menu
    void updateContextMenu(int) ;

  private slots:
    /// This slot is called by the examiner widgets gl area when a context menu is requested
    void slotCustomContextMenu( const QPoint& _point );

    /// called by plugins to add a new context menu
    void slotAddContextMenu(QMenu* _menu);

    /// called by plugins to add a real context menu depending on DataType
    void slotAddContextMenu( QMenu* _menu , DataType _dataType ,ContextMenuType type_);

Dirk Wilden's avatar
 
Dirk Wilden committed
404 405 406 407 408 409
    /// update globalOptions for actions in the contexMenu
    void updateGlobalOptions(bool _enable);

    /// change the background color
    void changeBackgroundColor();

Jan Möbius's avatar
 
Jan Möbius committed
410
  private :
Jan Möbius's avatar
Jan Möbius committed
411 412 413 414 415 416
    /** Update the contextmenu for the given position inside an examiner widget
     *
     * @param _point      Picking position in coordinates of the viewer
     * @param _examinerId Id of the examinerWidget used
     */
    void updatePopupMenu(const QPoint& _point, unsigned int _examinerId);
Jan Möbius's avatar
 
Jan Möbius committed
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

  private :
    /// context Menu for the gl area
    QMenu*  contextMenu_;

    /// Context Menu containing all selection elements
    QMenu*  contextSelectionMenu_;

    /// All context menu entries which will always be available
    std::vector< MenuInfo > persistentContextMenus_;

    /// All real context menu entries
    std::vector< MenuInfo > contextMenus_;

  /** @} */

  //===========================================================================
    /** @name StackWidget controls
    * @{ */
  //===========================================================================

  private slots:
    void slotGetStackWidget( QString _name, QWidget*& _widget );
    void slotAddStackWidget( QString _name, QWidget* _widget );
    void slotUpdateStackWidget( QString _name, QWidget* _widget );

    void slotViewMenuAction( QAction * _action);

    void slotUpdateStackMenu();


  private :
    /// QMenu containing the recently opened files
    QMenu* stackMenu_;

    std::vector< StackWidgetInfo > stackWidgetList_;

    /// Container widget for holding multiple views
    QStackedWidget* stackedWidget_;

  /** @} */

  //===========================================================================
  /** @name Help System
  * @{ */
  //===========================================================================

  public slots:
    /// Display the help Browser
    void showHelpBrowserUser();

    /// Display the help Browser
    void showHelpBrowserDeveloper();

  private:
    /// Pointer to the help Browser
    HelpWidget* helpBrowserDeveloper_;

    /// Pointer to the help Browser
    HelpWidget* helpBrowserUser_;

  /** @} */
479

Jan Möbius's avatar
Jan Möbius committed
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
  //===========================================================================
  /** @name About System
  * @{ */
  //===========================================================================

  public slots:
    /// Display the about widget
    void showAboutWidget();

  private:
    /// Pointer to the about widget
    AboutWidget* aboutWidget_;

  /** @} */

495 496 497 498 499 500 501 502 503 504 505
  //===========================================================================
  /** @name Options System
  * @{ */
  //===========================================================================

  public slots:
    /// Display the Options Browser
    void showOptionsWidget();

  signals:
    void applyOptions();
Dirk Wilden's avatar
Dirk Wilden committed
506
    void saveOptions();
Jan Möbius's avatar
Jan Möbius committed
507

508 509 510 511 512
  private:

    /// Pointer to the OptionsWidget
    OptionsWidget* optionsWidget_;

Jan Möbius's avatar
Jan Möbius committed
513 514
  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
515 516 517 518
  //===========================================================================
  /** @name ToolBar controls
  * @{ */
  //===========================================================================
Jan Möbius's avatar
Jan Möbius committed
519
  private slots:
Jan Möbius's avatar
 
Jan Möbius committed
520 521
    /// Called by Plugins to add a Toolbar
    void slotAddToolbar(QToolBar* _toolbar);
Jan Möbius's avatar
Jan Möbius committed
522

Jan Möbius's avatar
 
Jan Möbius committed
523 524 525
    /// Called by Plugins to remove a Toolbar
    void slotRemoveToolbar(QToolBar* _toolbar);

Jan Möbius's avatar
Jan Möbius committed
526 527 528
    /// Called by Plugins to get access to specific Toolbars by name
    void getToolBar( QString _name, QToolBar*& _toolbar);

Jan Möbius's avatar
 
Jan Möbius committed
529 530
  private :
    QToolBar* mainToolbar_;
Jan Möbius's avatar
Jan Möbius committed
531

Jan Möbius's avatar
Jan Möbius committed
532 533
    std::vector< QToolBar* > toolbars_;

Jan Möbius's avatar
Jan Möbius committed
534 535
  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
536 537 538 539 540 541
  //===========================================================================
  /** @name StatusBar controls
   * @{ */
  //===========================================================================
  public slots:
    void statusMessage(QString _message, int _timeout = 0);
Jan Möbius's avatar
Jan Möbius committed
542

Jan Möbius's avatar
 
Jan Möbius committed
543
    void clearStatusMessage();
Jan Möbius's avatar
Jan Möbius committed
544

Jan Möbius's avatar
 
Jan Möbius committed
545
    void setStatus( ApplicationStatus::applicationStatus _status);
Jan Möbius's avatar
Jan Möbius committed
546

Jan Möbius's avatar
 
Jan Möbius committed
547 548
  private:
    void setupStatusBar();
Jan Möbius's avatar
Jan Möbius committed
549

Jan Möbius's avatar
 
Jan Möbius committed
550 551
  private :
    QStatusBar* statusBar_;
Jan Möbius's avatar
Jan Möbius committed
552

Jan Möbius's avatar
 
Jan Möbius committed
553
    QLabel* statusIcon_;
Jan Möbius's avatar
Jan Möbius committed
554 555 556

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
557 558 559 560 561 562
  //===========================================================================
  /** @name Drag and Drop
   * @{ */
  //===========================================================================
  private slots:
    void startDrag( QMouseEvent* _event );
Jan Möbius's avatar
Jan Möbius committed
563

Jan Möbius's avatar
 
Jan Möbius committed
564
    void dragEnterEvent(QDragEnterEvent* _event);
Jan Möbius's avatar
Jan Möbius committed
565

Jan Möbius's avatar
 
Jan Möbius committed
566
    void dropEvent( QDropEvent* _event );
Jan Möbius's avatar
Jan Möbius committed
567 568 569

  /** @} */

Jan Möbius's avatar
 
Jan Möbius committed
570 571
  private :

Dirk Wilden's avatar
Dirk Wilden committed
572
  std::vector<PluginInfo>& plugins_;
Jan Möbius's avatar
 
Jan Möbius committed
573 574 575 576 577 578 579
};


//=============================================================================
#endif // COREWIDGET_HH defined
//=============================================================================