optionsWidget.cc 7.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//=============================================================================
//
//                               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.
Jan Möbius's avatar
Jan Möbius committed
15
//
16 17 18 19
//  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.
Jan Möbius's avatar
Jan Möbius committed
20
//
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
//  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: 1909 $
//   $Author: wilden $
//   $Date: 2008-06-03 18:45:21 +0200 (Tue, 03 Jun 2008) $
//
//=============================================================================




#include "optionsWidget.hh"
#include <iostream>
#include <OpenFlipper/common/GlobalOptions.hh>
Jan Möbius's avatar
Jan Möbius committed
38
#include <QtNetwork>
Dirk Wilden's avatar
Dirk Wilden committed
39 40 41


OptionsWidget::OptionsWidget(std::vector<PluginInfo>& _plugins, std::vector<KeyBinding>& _core, QWidget *parent)
Jan Möbius's avatar
Jan Möbius committed
42 43 44 45
  : QWidget(parent),
    plugins_(_plugins),
    coreKeys_(_core)

46 47
{
  setupUi(this);
Dirk Wilden's avatar
Dirk Wilden committed
48

49 50
  connect(applyButton,SIGNAL(clicked()),this,SLOT(slotApply()));
  connect(cancelButton,SIGNAL(clicked()),this,SLOT(slotCancel()));
Jan Möbius's avatar
Jan Möbius committed
51 52 53 54
//   connect(checkUpdateButton,SIGNAL(clicked()),this,SLOT(slotCheckUpdates()));



55 56 57
}

void OptionsWidget::showEvent ( QShowEvent * event ) {
Dirk Wilden's avatar
Dirk Wilden committed
58

Jan Möbius's avatar
Jan Möbius committed
59
  //general
Dirk Wilden's avatar
Dirk Wilden committed
60 61 62 63
  fullscreen->setChecked( OpenFlipper::Options::fullScreen() );
  splash->setChecked( OpenFlipper::Options::splash() );
  toolbox->setChecked( !OpenFlipper::Options::hideToolbox() );
  logger->setChecked( !OpenFlipper::Options::hideLogger() );
Dirk Wilden's avatar
Dirk Wilden committed
64
  enableLogFile->setChecked( OpenFlipper::Options::logFileEnabled() );
Jan Möbius's avatar
Jan Möbius committed
65

Dirk Wilden's avatar
Dirk Wilden committed
66 67
  //paths
  logFile->setText( OpenFlipper::Options::logFile() );
Dirk Wilden's avatar
Dirk Wilden committed
68 69 70 71 72 73

  //viewer
  backfaceCulling->setChecked( OpenFlipper::Options::backfaceCulling() );
  wZoomFactor->setText( QString::number(OpenFlipper::Options::wheelZoomFactor(), 'f') );
  wZoomFactorShift->setText( QString::number(OpenFlipper::Options::wheelZoomFactorShift(), 'f') );

Dirk Wilden's avatar
Dirk Wilden committed
74
  //keyBindings
75 76
  keyTree->clear();

Dirk Wilden's avatar
Dirk Wilden committed
77 78 79 80 81 82 83 84 85 86 87 88 89
  keyTree->setColumnCount ( 2 );

  QStringList headerdata;
  headerdata << "Action" << "Shortcut";
  keyTree->setHeaderLabels(headerdata);

  //add Core Keys
  QTreeWidgetItem * core = new QTreeWidgetItem(keyTree, QStringList("CoreWidget"));

  QList<QTreeWidgetItem *> keys;

  for (uint i=0; i < coreKeys_.size(); i++){
    QStringList row;
Jan Möbius's avatar
Jan Möbius committed
90 91
    QKeySequence keySequence( coreKeys_[i].key + coreKeys_[i].modifiers );
    row << coreKeys_[i].description << keySequence.toString();
Dirk Wilden's avatar
Dirk Wilden committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    keys.append(new QTreeWidgetItem(core, row));
  }

  core->addChildren(keys);
  keyTree->addTopLevelItem( core );



  QList<QTreeWidgetItem *> plugins;

  for (uint i=0; i < plugins_.size(); i++){
    plugins.append(new QTreeWidgetItem(keyTree, QStringList( plugins_[i].name )));

    QList<QTreeWidgetItem *> keys;

    for (int k=0; k < plugins_[i].keys.count(); k++){
      QStringList row;
Jan Möbius's avatar
Jan Möbius committed
109 110
      QKeySequence keySequence( plugins_[i].keys[k].key + plugins_[i].keys[k].modifiers );
      row << plugins_[i].keys[k].description << keySequence.toString();
Dirk Wilden's avatar
Dirk Wilden committed
111 112 113 114 115 116 117 118 119 120 121
      keys.append(new QTreeWidgetItem(plugins[i], row));
    }

    plugins[i]->addChildren(keys);

  }

  keyTree->addTopLevelItems( plugins );

  keyTree->resizeColumnToContents(0);
  keyTree->resizeColumnToContents(1);
122 123 124
}

void OptionsWidget::slotApply() {
Dirk Wilden's avatar
Dirk Wilden committed
125

Jan Möbius's avatar
Jan Möbius committed
126
  //general
Dirk Wilden's avatar
Dirk Wilden committed
127 128 129 130
  OpenFlipper::Options::fullScreen( fullscreen->isChecked() );
  OpenFlipper::Options::splash( splash->isChecked() );
  OpenFlipper::Options::hideToolbox( !toolbox->isChecked() );
  OpenFlipper::Options::hideLogger( !logger->isChecked() );
Dirk Wilden's avatar
Dirk Wilden committed
131 132 133 134
  OpenFlipper::Options::logFileEnabled( enableLogFile->isChecked() );

  //paths
  OpenFlipper::Options::logFile( logFile->text() );
Dirk Wilden's avatar
Dirk Wilden committed
135 136 137 138 139 140

  //viewer
  OpenFlipper::Options::backfaceCulling( backfaceCulling->isChecked() );
  OpenFlipper::Options::wheelZoomFactor( wZoomFactor->text().toDouble() );
  OpenFlipper::Options::wheelZoomFactorShift( wZoomFactorShift->text().toDouble() );

141
  emit applyOptions();
Dirk Wilden's avatar
Dirk Wilden committed
142
  emit saveOptions();
143 144 145 146 147 148
  hide();
}

void OptionsWidget::slotCancel() {
  hide();
}
Jan Möbius's avatar
Jan Möbius committed
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

// void OptionsWidget::slotCheckUpdates() {
// //   QUrl url("https://www.graphics.rwth-aachen.de/restricted/OpenFlipper-SIL/Versions.txt");
// //   url.setUserName("");
// //   url.setPassord("");
//
//   QString ServerMainURL = updateURL->text() + "Versions.txt";
//   QUrl url(ServerMainURL);
//
//   if ( ! updateUser->text().isEmpty() )
//     url.setUserName(updateUser->text());
//
//   if ( ! updatePass->text().isEmpty() )
//     url.setPassword(updatePass->text());
//
//   QFileInfo fileInfo( QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() +
//                       ".OpenFlipper" + OpenFlipper::Options::dirSeparator() + "ServerVersions.txt");
//   QString fileName = fileInfo.filePath();
//
//   if (QFile::exists(fileName)) {
//     QFile::remove(fileName);
//     std::cerr << "File exists, removing it" << std::endl;
//   }
//
//    file = new QFile(fileName);
//   if (!file->open(QIODevice::WriteOnly)) {
//     std::cerr << "Unable to Open local file for writing" << std::endl;
//     delete file;
//     file = 0;
//   } else {
//     QHttp* http = new QHttp;
//     QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
//     http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port());
//
//     if (!url.userName().isEmpty())
//         http->setUser(url.userName(), url.password());
//
// //     httpRequestAborted = false;
//     QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/");
//     if (path.isEmpty())
//       path = "/";
//
//     int httpGetId = http->get(path, file);
//
//     // !!! Does not work because get is non blocking
//     file->close();
//
//     delete file;
//
// //     progressDialog->setWindowTitle(tr("HTTP"));
// //     progressDialog->setLabelText(tr("Downloading %1.").arg(fileName));
// //     downloadButton->setEnabled(false);
//   }
// }
//
//  void HttpWindow::httpRequestFinished(int requestId, bool error)
//  {
//      if (requestId != httpGetId)
//          return;
//      if (httpRequestAborted) {
//          if (file) {
//              file->close();
//              file->remove();
//              delete file;
//              file = 0;
//          }
//
//          progressDialog->hide();
//          return;
//      }
//
//      if (requestId != httpGetId)
//          return;
//
//      progressDialog->hide();
//      file->close();
//
//      if (error) {
//          file->remove();
//          QMessageBox::information(this, tr("HTTP"),
//                                   tr("Download failed: %1.")
//                                   .arg(http->errorString()));
//      } else {
//          QString fileName = QFileInfo(QUrl(urlLineEdit->text()).path()).fileName();
//          statusLabel->setText(tr("Downloaded %1 to current directory.").arg(fileName));
//      }
//
//      downloadButton->setEnabled(true);
//      delete file;
//      file = 0;
//  }