optionsWidget.hh 8.08 KB
Newer Older
1
/*===========================================================================*\
Jan Möbius's avatar
Jan Möbius committed
2 3
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39
*                                                                            *
40 41
\*===========================================================================*/

42

43 44 45 46 47 48 49




#ifndef OPTIONSWIDGET_HH
#define OPTIONSWIDGET_HH

50 51 52
#include <OpenFlipper/Core/PluginInfo.hh>
#include <ACG/Scenegraph/DrawModes.hh>

53
#include "ui_optionsWidget.h"
Matthias Möller's avatar
Matthias Möller committed
54

55
#include <QStringList>
56
#include <QProgressDialog>
Jan Möbius's avatar
Jan Möbius committed
57
#include <QtNetwork>
58

Dirk Wilden's avatar
Dirk Wilden committed
59

Dirk Wilden's avatar
Dirk Wilden committed
60 61 62 63
//map for keyBindings
typedef std::multimap< std::pair< QObject*, int >, std::pair< int, Qt::KeyboardModifiers > > InverseKeyMap;


64 65
class OptionsWidget : public QWidget, public Ui::OptionsWidget
{
Jan Möbius's avatar
Jan Möbius committed
66

Jan Möbius's avatar
Jan Möbius committed
67
Q_OBJECT
68

Jan Möbius's avatar
Jan Möbius committed
69
public:
Dirk Wilden's avatar
Dirk Wilden committed
70
   OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, InverseKeyMap& _invKeys, QWidget* parent =0 );
71

Jan Möbius's avatar
Jan Möbius committed
72 73 74
signals:
   void applyOptions();
   void saveOptions();
75

Dirk Wilden's avatar
Dirk Wilden committed
76 77
   void addKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID);

Jan Möbius's avatar
Jan Möbius committed
78
private slots:
Dirk Wilden's avatar
Dirk Wilden committed
79 80 81
   /// call slotApply and hide widget
   void slotOk();
   /// Update Options and tell others about changed Options
Jan Möbius's avatar
Jan Möbius committed
82
   void slotApply();
83

Jan Möbius's avatar
Jan Möbius committed
84 85
   /// Only hide widget
   void slotCancel();
Jan Möbius's avatar
Jan Möbius committed
86

Jan Möbius's avatar
Jan Möbius committed
87 88
   /// Checks for updates
   void slotCheckUpdates();
Jan Möbius's avatar
Jan Möbius committed
89

Jan Möbius's avatar
Jan Möbius committed
90 91
   /// Download updates
   void slotGetUpdates();
Jan Möbius's avatar
Jan Möbius committed
92

Jan Möbius's avatar
Jan Möbius committed
93 94
   /// open a dialog to determine the color
   void getBackgroundColor();
95
   void getDefaultColor();
96

Dirk Wilden's avatar
Dirk Wilden committed
97 98 99 100 101 102 103
   /// keyBinding TreeWidget-Item changed
   void keyTreeItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous );

   void keyTreeDoubleClicked(QTreeWidgetItem* _item, int col);

   void updateShortcut();

Dirk Wilden's avatar
Dirk Wilden committed
104 105
   void slotShowPluginOptions(const QString& _pluginName );

106 107 108
   ///restore keyBinding Presets
   void restoreKeyPresets();

109 110 111 112 113 114 115
   /// update the dialog if the selected viewer changes
   void updateViewerSettings(int _row);

   /// remember user changes to viewer properties
   void viewerSettingsChanged(QListWidgetItem* _item);
   void viewerSettingsChanged(int _index);

116 117 118
   /// Switch between the stacked widgets of the stereo settings
   void switchStackedWidget();

119 120 121 122
   /// This function is called to update stereo settings for real-time preview
   /// Note: The parameter only makes sure that the signals can be connected
   /// to this slot.
   void slotPreviewStereoSettings(int _tmpParam = 0);
123 124 125 126 127 128
   
   /// Clear all OpenFlipper settings
   void slotClearSettings();
   
   /// Clear OpenFlipper INI
   void slotClearINI();
129

130 131 132
   /// Clear the Shader Cache
   void slotReloadShaders();

Jan Möbius's avatar
Jan Möbius committed
133 134
protected:
   void showEvent ( QShowEvent * event );
Dirk Wilden's avatar
Dirk Wilden committed
135

Jan Möbius's avatar
Jan Möbius committed
136
private:
Dirk Wilden's avatar
Dirk Wilden committed
137

Dirk Wilden's avatar
Dirk Wilden committed
138 139 140 141 142
   // plugin Options
   void initPluginOptions();

   QVBoxLayout* pluginOptionsLayout;

Jan Möbius's avatar
Jan Möbius committed
143 144 145
   //key-bindings
   std::vector<PluginInfo>& plugins_;
   std::vector<KeyBinding>& coreKeys_;
Jan Möbius's avatar
Jan Möbius committed
146

Dirk Wilden's avatar
Dirk Wilden committed
147 148 149 150 151 152 153 154
   InverseKeyMap& keys_;

   int getPluginInfo(QString pluginName);

   void initKeyTree();

   void applyShortcuts();

Jan Möbius's avatar
Jan Möbius committed
155 156
   // flag indicating if something went wrong and the request has to be aborted
   bool httpRequestAborted;
Jan Möbius's avatar
Jan Möbius committed
157 158


Jan Möbius's avatar
Jan Möbius committed
159
   // Request variable
160 161 162
   QNetworkAccessManager *networkMan_;
   // current request
   QNetworkReply* downloadRep_;
Jan Möbius's avatar
Jan Möbius committed
163

Jan Möbius's avatar
Jan Möbius committed
164 165
   // File for http downloads
   QFile *file;
Jan Möbius's avatar
Jan Möbius committed
166

Jan Möbius's avatar
Jan Möbius committed
167
   // ProgressDialog for Downloads
168
   QProgressDialog *progressDialog_;
Jan Möbius's avatar
Jan Möbius committed
169

Jan Möbius's avatar
Jan Möbius committed
170 171
   // What type of download is currently active
   enum DOWNLOAD {
Jan Möbius's avatar
Jan Möbius committed
172 173
      NONE,
      VERSIONS_FILE,
Jan Möbius's avatar
Jan Möbius committed
174
      PLUGIN,
Jan Möbius's avatar
Jan Möbius committed
175
      WINDOWS_SETUP
Jan Möbius's avatar
Jan Möbius committed
176
   } downloadType;
Jan Möbius's avatar
Jan Möbius committed
177

178
  // remember changes to viewer properties
179
  std::vector< ACG::SceneGraph::DrawModes::DrawMode > defaultDrawModes_;
180
  std::vector< bool >  defaultProjectionMode_;
181 182
  std::vector< int >   defaultViewingDirections_;
  std::vector< bool >  defaultRotationLocks_;
183 184

  bool updatingViewerSettings_;
185 186 187
  
  // Store current background color
  QColor backgroundColor_;
188

Jan Möbius's avatar
Jan Möbius committed
189 190 191
private:
   /// Starts the download of the given file
   void startDownload( QString _url );
Jan Möbius's avatar
Jan Möbius committed
192

Jan Möbius's avatar
Jan Möbius committed
193 194
   /// Compares the versions from the downloaded Versions file with the current versions
   void compareVersions();
195

Jan Möbius's avatar
Jan Möbius committed
196 197
   /// Compares two version strings and returns if a newer Version is available
   bool isNewer(QString _current, QString _latest);
198

Jan Möbius's avatar
Jan Möbius committed
199 200
   /// Redraws the version table
   void updateVersionsTable();
Jan Möbius's avatar
Jan Möbius committed
201

Jan Möbius's avatar
Jan Möbius committed
202
private slots:
Jan Möbius's avatar
Jan Möbius committed
203

Jan Möbius's avatar
Jan Möbius committed
204
   // This slot is called when a http request has been finished
205
   void httpRequestFinished(QNetworkReply *_qnr);
Jan Möbius's avatar
Jan Möbius committed
206

Jan Möbius's avatar
Jan Möbius committed
207
   // Updates the progress Dialog while downloading
208 209 210 211
   void updateDataReadProgress(qint64 _bytesReceived, qint64 _bytesTotal);

   /// error occured while downloading
   void showError(QNetworkReply::NetworkError _error);
Jan Möbius's avatar
Jan Möbius committed
212 213 214 215 216 217

   // Progress dialog callback for cancel
   void cancelDownload();

   // Update component of OpenFlipper
   void updateComponent();
218 219 220
   
   // Tracks whether another language has been selected
   void slotTranslationIndexChanged(int);
Jan Möbius's avatar
Jan Möbius committed
221

222 223 224
   /// authentication
   void authentication  ( QNetworkReply* _reply, QAuthenticator* _authenticator );

Jan Möbius's avatar
Jan Möbius committed
225 226 227 228 229 230 231 232 233 234 235 236
private:
   /** After checking for updates this variable will contain a list of filenames for which updates are available
    */
   QStringList updatedPlugins_;

   /** Here the architecture specific path for plugins will be created
    */
   QString pluginPath_;

   /** Current filename of the plugin to be updated
    */
   QString currentUpdateName_;
237 238 239
   
   /** Used to track whether another language has been selected
   */
240
   bool restartRequired_;
241
   bool exitOnClose_;
Jan Möbius's avatar
Jan Möbius committed
242 243


244 245 246
};

#endif //OPTIONSWIDGET_HH