Commit b524e0a6 authored by Jan Möbius's avatar Jan Möbius

Dennis:

* Replaced QDockWidgets/Area with own implementation
* Use QSettings to store geometry and states of all widgets/windows

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@5202 383ad7c9-94d9-4d36-a494-682f7c89f535
parent ff8821f2
......@@ -59,6 +59,7 @@
#include <QStatusBar>
#include <QMessageBox>
#include <QFile>
#include <QSettings>
#include <QPluginLoader>
#include "OpenFlipper/BasePlugin/BaseInterface.hh"
......@@ -476,32 +477,28 @@ Core::init() {
if ( OpenFlipper::Options::gui() ) {
//try to restore the windowState
QFile file(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "windowState.dat");
if (file.open(QIODevice::ReadOnly)){
QByteArray bytes = file.readAll();
coreWidget_->restoreState( bytes );
file.close();
}
QSettings windowStates(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "WindowStates.dat", QSettings::IniFormat);
//try to restore the windowState
coreWidget_->restoreState (windowStates.value("Core/Window/State").toByteArray ());
//try to restore the geometry
QFile file2(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "geometry.dat");
if (file2.open(QIODevice::ReadOnly)){
QByteArray bytes = file2.readAll();
coreWidget_->restoreGeometry( bytes );
coreWidget_->restoreGeometry (windowStates.value("Core/Window/Geometry").toByteArray ());
file2.close();
}
coreWidget_->toolSplitter_->restoreState (windowStates.value("Core/ToolSplitter").toByteArray ());
coreWidget_->splitter_->restoreState (windowStates.value("Core/LogSplitter").toByteArray ());
coreWidget_->show();
applyOptions();
windowStates.beginGroup ("Core");
windowStates.beginGroup ("LogSlider");
coreWidget_->slidingLogger_->restoreState (windowStates);
windowStates.endGroup ();
coreWidget_->toolBox_->restoreState (windowStates);
windowStates.endGroup ();
if ( OpenFlipper::Options::splash() ) {
splash_->finish(coreWidget_);
}
......@@ -835,20 +832,22 @@ Core::writeOnExit() {
//store the windowState
if ( OpenFlipper::Options::gui() ) {
QFile file(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "windowState.dat");
if (file.open(QIODevice::WriteOnly))
{
file.write( coreWidget_->saveState() );
file.close();
}
QFile file2(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "geometry.dat");
if (file2.open(QIODevice::WriteOnly))
{
file2.write( coreWidget_->saveGeometry() );
file2.close();
}
QSettings windowStates(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "WindowStates.dat", QSettings::IniFormat);
windowStates.setValue("Core/Window/State", coreWidget_->saveState ());
windowStates.setValue("Core/Window/Geometry", coreWidget_->saveGeometry ());
windowStates.setValue ("Core/ToolSplitter", coreWidget_->toolSplitter_->saveState ());
windowStates.setValue ("Core/LogSplitter", coreWidget_->splitter_->saveState ());
windowStates.beginGroup ("Core");
windowStates.beginGroup ("LogSlider");
coreWidget_->slidingLogger_->saveState (windowStates);
windowStates.endGroup ();
coreWidget_->toolBox_->saveState (windowStates);
windowStates.endGroup ();
}
// Call exit for all plugins
......
......@@ -87,7 +87,7 @@ class PluginInfo{
QList< KeyBinding > keys;
/// Pointer to plugins toolbar widget (if available)
QDockWidget* widget;
QWidget* widget;
/// Pointer to plugins options widget (if available)
QWidget* optionsWidget;
......
......@@ -583,29 +583,7 @@ void Core::loadPlugin(QString filename, bool silent){
QWidget* widget = 0;
if ( toolboxPlugin->initializeToolbox( widget ) ) {
QDockWidget* dock = new QDockWidget(info.name , coreWidget_ );
QScrollArea* scrollArea = new QScrollArea(dock);
scrollArea->setWidget(widget);
scrollArea->setWidgetResizable(true);
dock->setWidget(scrollArea);
dock->setMaximumWidth(400);
// std::cerr << info.name.toStdString() << std::endl;
// std::cerr << "minimumSizeHint : " << widget->minimumSizeHint().width() << std::endl;
// std::cerr << "minimumSize : " << widget->minimumSize().width() << std::endl;
int newNumber = toolboxindex_;
toolboxindex_++;
QString number = QString::number(newNumber);
dock->setObjectName( "ToolWidget" + number );
coreWidget_->setDockOptions(QMainWindow::AllowTabbedDocks | QMainWindow::VerticalTabs);
coreWidget_->addDockWidget(Qt::RightDockWidgetArea,dock);
connect(dock, SIGNAL( visibilityChanged (bool) ), coreWidget_ , SLOT( slotVisibilityChanged(bool) ));
info.widget = dock;
info.widget = widget;
// add widget name to viewMode 'all'
QString name_nospace = info.name;
......@@ -1014,10 +992,6 @@ void Core::loadPlugin(QString filename, bool silent){
plugins.push_back(info);
//tab all dockwidgets together
if (OpenFlipper::Options::gui())
coreWidget_->tabDockWidgets( QVector< QDockWidget* >() );
// Initialize Plugin
if ( basePlugin ) {
if ( checkSlot(plugin,"initializePlugin()") )
......
......@@ -99,13 +99,8 @@ void Core::applyOptions(){
//hideToolbox
if (OpenFlipper::Options::hideToolbox()) {
//hide all toolWidgets
for (uint p=0; p < plugins.size(); p++)
if (plugins[p].widget)
plugins[p].widget->setVisible(false);
//hide ViewMode Selection Widget
coreWidget_->dockViewMode_->setVisible(false);
coreWidget_->showToolbox (false);
}
//setup logFile
......
......@@ -68,7 +68,6 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
coreSlots_(_coreSlots),
shiftPressed_(false),
viewModes_(_viewModes),
dockViewMode_(0),
viewModeButton_(0),
viewModeMenu_(0),
viewGroup_(0),
......@@ -99,8 +98,11 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
{
setupStatusBar();
splitter_ = new QSplitter(Qt::Vertical,this);
setCentralWidget(splitter_);
toolSplitter_ = new QSplitter(Qt::Horizontal,this);
setCentralWidget(toolSplitter_);
splitter_ = new QSplitter(Qt::Vertical,toolSplitter_);
stackedWidget_ = new QStackedWidget(splitter_);
QGLFormat format;
......@@ -440,18 +442,39 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
originalLoggerSize_ = wsizes[1];
// ======================================================================
// Create Upper DockWidget for ToolWidget control
// Create ToolBox area
// ======================================================================
dockViewMode_ = new QDockWidget("ViewMode" , this );
dockViewMode_->setObjectName("DockViewMode");
QPushButton* button = new QPushButton("Change View Mode");
dockViewMode_->setWidget(button);
button->setParent(dockViewMode_);
dockViewMode_->setFeatures( QDockWidget::NoDockWidgetFeatures );
button->show();
addDockWidget(Qt::RightDockWidgetArea,dockViewMode_);
connect(button, SIGNAL(clicked()), this, SLOT(slotViewModeDialog()));
dockViewMode_->setVisible(false);
toolBoxArea_ = new QWidget (toolSplitter_);
QGroupBox *gb = new QGroupBox ("ViewMode");
QHBoxLayout *hLayout = new QHBoxLayout;
QPushButton* vmButton = new QPushButton("Change View Mode");
hLayout->addWidget (vmButton);
gb->setLayout (hLayout);
connect(vmButton, SIGNAL(clicked()), this, SLOT(slotViewModeDialog()));
toolBoxScroll_ = new QScrollArea ();
toolBox_ = new SideArea ();
toolBoxScroll_->setWidget (toolBox_);
toolBoxScroll_->setWidgetResizable (true);
toolBoxScroll_->setFrameStyle (QFrame::StyledPanel);
QVBoxLayout *vLayout = new QVBoxLayout;
vLayout->addWidget(gb);
vLayout->addWidget(toolBoxScroll_);
toolBoxArea_->setLayout (vLayout);
wsizes = toolSplitter_->sizes();
wsizes[0] = 480;
wsizes[1] = 240;
toolSplitter_->setSizes(wsizes);
// ======================================================================
// Context menu setup
......@@ -679,13 +702,9 @@ CoreWidget::showToolbox( bool _state ) {
OpenFlipper::Options::hideToolbox( !_state );
if ( OpenFlipper::Options::hideToolbox() ){
//hide all toolWidgets
for (uint p=0; p < plugins_.size(); p++)
if (plugins_[p].widget)
plugins_[p].widget->setVisible(false);
//hide ViewMode Selection Widget
dockViewMode_->setVisible(false);
toolBoxArea_->setVisible(false);
}else{
//reset last ViewMode
......@@ -693,6 +712,7 @@ CoreWidget::showToolbox( bool _state ) {
setViewMode("All");
else
setViewMode( OpenFlipper::Options::defaultToolboxMode() );
toolBoxArea_->setVisible(true);
}
}
......
......@@ -56,6 +56,7 @@
#include <OpenFlipper/BasePlugin/ViewInterface.hh>
#include <OpenFlipper/BasePlugin/StatusbarInterface.hh>
#include <OpenFlipper/widgets/coreWidget/SideArea.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <OpenFlipper/widgets/glWidget/QtGLGraphicsScene.hh>
......@@ -84,6 +85,7 @@
#include <OpenFlipper/INIFile/INIFile.hh>
struct ViewMode{
QString name;
bool custom; //is the mode defined by the user?
......@@ -320,9 +322,6 @@ public:
/// List of currently available viewModes
QVector<ViewMode*>& viewModes_;
///DockWidget and Button for changing viewMode via dialog
QDockWidget* dockViewMode_;
private:
QPushButton* viewModeButton_;
......@@ -333,10 +332,6 @@ public:
/// Group for all menu items
QActionGroup* viewGroup_;
public:
/// Tab all DockWidgets which belong to ToolWidgets together
void tabDockWidgets(QVector< QDockWidget* > _widgets);
public slots:
/// init ViewModes that were loaded via ini-file
......@@ -362,9 +357,6 @@ public:
/// 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 );
......@@ -419,6 +411,18 @@ public:
/// Temporary widget
QWidget* tempLogWidget;
/// Widget for toolBox
QWidget* toolBoxArea_;
/// Spliter between toplevel objects and toolbox
QSplitter* toolSplitter_;
/// Toolbox
SideArea* toolBox_;
/// Toolbox scroll area
QScrollArea* toolBoxScroll_;
// widget showing the scenegraph
ACG::QtWidgets::QtSceneGraphDialog* sceneGraphDialog_;
......
//=============================================================================
//
// 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: $
//
//=============================================================================
//== INCLUDES =================================================================
#include <QVBoxLayout>
#include "SideArea.hh"
#include "SideElement.hh"
//== IMPLEMENTATION ==========================================================
SideArea::SideArea (QWidget *_parent) :
QWidget (_parent)
{
layout_ = new QVBoxLayout;
layout_->setSpacing (0);
QVBoxLayout *l = new QVBoxLayout;
l->addLayout (layout_);
l->addStretch(1);
setLayout (l);
}
//-----------------------------------------------------------------------------
void SideArea::addItem (QWidget *_w, QString _name)
{
SideElement *e = new SideElement (this, _w, _name);
layout_->addWidget (e);
items_.push_back (e);
}
//-----------------------------------------------------------------------------
void SideArea::clear ()
{
foreach (SideElement *e, items_)
{
layout_->removeWidget (e);
delete e;
}
items_.clear ();
}
//-----------------------------------------------------------------------------
void SideArea::saveState (QSettings &_settings)
{
_settings.beginGroup ("SideArea");
foreach (SideElement *e, items_)
{
e->saveState (_settings);
}
_settings.endGroup ();
}
//-----------------------------------------------------------------------------
void SideArea::restoreState (QSettings &_settings)
{
_settings.beginGroup ("SideArea");
foreach (SideElement *e, items_)
{
e->restoreState (_settings);
}
_settings.endGroup ();
}
//=============================================================================
//=============================================================================
//=============================================================================
//
// 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: $
//
//=============================================================================
#ifndef SIDE_AREA_
#define SIDE_AREA_
//=============================================================================
//
// CLASS SideElement
//
//=============================================================================
//== INCLUDES =================================================================
#include <QWidget>
#include <QString>
#include <QSettings>
//== FORWARDDECLARATIONS ======================================================
class QVBoxLayout;
class SideElement;
/** \class SideArea SideArea.hh <OpenFlipper/widgets/coreWidget/SideArea.hh>
A widget that holds the different plugin tool widgets
**/
class SideArea : public QWidget {
public:
/** Create a SideElement
\param _parent Parent widget
*/
SideArea (QWidget *_parent = 0);
/** Adds a plugin tool widget
\param _w Plugin widget
\param _name Plugin name
*/
void addItem (QWidget *_w, QString _name);
/// clears the whole tool widget area
void clear ();
/// returns the current state
void saveState (QSettings &_settings);
/// restores the state
void restoreState (QSettings &_settings);
private:
// elements
QVector<SideElement *> items_;
// main layout
QVBoxLayout *layout_;
};
//=============================================================================
//=============================================================================
#endif // SIDE_AREA_ defined
//=============================================================================
\ No newline at end of file
//=============================================================================
//
// 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: $
//
//=============================================================================
//== INCLUDES =================================================================
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QToolButton>
#include <QAction>
#include <QFrame>
#include <QMouseEvent>
#include <QFont>
#include <QDialog>
#include <OpenFlipper/common/GlobalOptions.hh>
#include "SideElement.hh"
//== IMPLEMENTATION ==========================================================
SideElement::SideElement (SideArea *_parent, QWidget *_w, QString _name) :
parent_ (_parent),
widget_ (_w),
name_ (_name),
active_ (0),
dialog_ (0)
{
QFont font;
font.setBold (false);
QHBoxLayout *hl = new QHBoxLayout;
SideElement::TopArea *tr = new SideElement::TopArea (this);
label_ = new QLabel (_name);
label_->setFont (font);
detachButton_ = new QToolButton ();
hl->addWidget (label_);
hl->addStretch (1);
hl->addWidget (detachButton_);
detachAction_ = new QAction (QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+"button-detach.png"), "", this);
detachAction_->setToolTip ("Show as separate window.");
detachAction_->setCheckable (true);
detachButton_->setDefaultAction (detachAction_);
connect (detachAction_, SIGNAL (triggered (bool)), this, SLOT (detachPressed (bool)));
tr->setLayout (hl);
QFrame *f = new QFrame ();
f->setFrameShape (QFrame::HLine);
mainLayout_ = new QVBoxLayout;
mainLayout_->addWidget (f);
mainLayout_->addWidget (tr);
mainLayout_->addWidget (_w);
mainLayout_->setSpacing (0);
mainLayout_->setContentsMargins (1,1,1,1);
setLayout (mainLayout_);
_w->hide ();
}
//-----------------------------------------------------------------------------
SideElement::~SideElement ()
{
if (dialog_)
dialog_->close ();
widget_->setParent (0);
}
//-----------------------------------------------------------------------------
void SideElement::labelPress ()
{
if (dialog_)
{
dialog_->raise ();
dialog_->activateWindow ();
}
else
{
active_ = !active_;
if (active_)
widget_->show ();
else
widget_->hide ();
QFont font;
font.setBold (active_);
label_->setFont (font);
}
}
//-----------------------------------------------------------------------------
void SideElement::detachPressed (bool checked_)
{
if (checked_)
{
mainLayout_->removeWidget (widget_);
dialog_ = new QDialog(0, Qt::CustomizeWindowHint | Qt::WindowTitleHint);
dialog_->setWindowTitle (name_);