layoutSettingsWidget.cpp

Go to the documentation of this file.
00001 //==============================================
00002 //  copyright            : (C) 2003-2005 by Will Stokes
00003 //==============================================
00004 //  This program is free software; you can redistribute it
00005 //  and/or modify it under the terms of the GNU General
00006 //  Public License as published by the Free Software
00007 //  Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //==============================================
00010 
00011 //Systemwide includes
00012 #include <qlayout.h>
00013 #include <qlabel.h>
00014 #include <qfont.h>
00015 #include <qcheckbox.h>
00016 #include <qframe.h>
00017 #include <qslider.h>
00018 #include <qspinbox.h>
00019 #include <qvgroupbox.h>
00020 #include <qpushbutton.h>
00021 #include <qcombobox.h>
00022 #include <qapplication.h>
00023 #include <qtooltip.h>
00024 
00025 //Projectwide includes
00026 #include "layoutSettingsWidget.h"
00027 #include "configuration.h"
00028 #include "../config.h"
00029 #include "../gui/window.h"
00030 #include "../gui/titleWidget.h"
00031 
00032 //==============================================
00033 LayoutSettingsWidget::LayoutSettingsWidget( Configuration* config,
00034                                             QWidget* parent,
00035                                             const char* name ) : QWidget( parent, name)
00036 {
00037   this->config = config;
00038 
00039   categoryLabel = new QLabel( tr("Appearance:"), this);
00040   QFont labelFont = categoryLabel->font();
00041   labelFont.setWeight(QFont::Bold);
00042   categoryLabel->setFont( labelFont );
00043 
00044   horizontalLine = new QFrame(this);
00045   horizontalLine->setLineWidth(2);
00046   horizontalLine->setMidLineWidth(1);
00047   horizontalLine->setFrameStyle( QFrame::HLine | QFrame::Raised );
00048   //----------------
00049   //General Settings:
00050   //-display image animations
00051   //-display tooltips
00052   generalSettings = new QVGroupBox( tr("General"), this);
00053   useAnimation = new QCheckBox( tr("Use animation"), generalSettings);
00054   showTooltips = new QCheckBox( tr("Show tooltips"), generalSettings);
00055   //----------------
00056   //Window placement and size Settings:
00057   //-restore old placement and size
00058   //-preset default size (% of screen size) and placement
00059   windowPlacementSize = new QVGroupBox( tr("Window Placement and Size"), this);
00060   restoreWindowPlacementSize = new QCheckBox( tr("Restore window placement and size"), windowPlacementSize);
00061 
00062   sizeFrame = new QFrame(windowPlacementSize);
00063   defaultWindowSizeLabel = new QLabel( tr("% of Screen:"), sizeFrame);
00064   defaultWindowSizeSlider = new QSlider(Qt::Horizontal, sizeFrame);
00065   defaultWindowSizeSlider->setMinValue(1);
00066   defaultWindowSizeSlider->setMaxValue(100);
00067   defaultWindowSizeValue = new QSpinBox(1,100,1,sizeFrame);
00068   defaultWindowSizeValue->setSuffix("%");
00069 
00070   defaultWindowPlacementLabel = new QLabel( tr("Placement:"), sizeFrame);
00071   defaultWindowPlacement = new QComboBox( sizeFrame );
00072   defaultWindowPlacement->insertItem( tr("Center") );
00073   defaultWindowPlacement->insertItem( tr("Top Left") );
00074   defaultWindowPlacement->insertItem( tr("Top Right") );
00075   defaultWindowPlacement->insertItem( tr("Bottom Left") );
00076   defaultWindowPlacement->insertItem( tr("Bottom Right") );
00077 
00078   //update spinbox value when slider moves
00079   connect( defaultWindowSizeSlider, SIGNAL(valueChanged(int)),
00080                    this, SLOT(defaultSizeSliderMoved(int)) );;
00081 
00082   //update slider when spinbox changes
00083   connect( defaultWindowSizeValue, SIGNAL(valueChanged(int)),
00084                    this, SLOT(defaultSizeSpinboxChanged(int)) );;
00085 
00086   //disable manual window size/placement settings when auto save position/location is checked
00087   connect( restoreWindowPlacementSize, SIGNAL(toggled(bool)),
00088                    this, SLOT(toggleDefaultSizeEnabled(bool)) );;
00089   //----------------
00090   //place window placement/size control in box grid
00091   manualPlacementGrid = new QGridLayout( sizeFrame, 2, 3, 0);  
00092   manualPlacementGrid->setSpacing( WIDGET_SPACING );
00093 
00094   manualPlacementGrid->addWidget(defaultWindowSizeLabel,  0, 0);
00095   manualPlacementGrid->addWidget(defaultWindowSizeSlider, 0, 1);
00096   manualPlacementGrid->setColStretch(1, 1);
00097   manualPlacementGrid->addWidget(defaultWindowSizeValue,  0, 2);
00098 
00099   manualPlacementGrid->addWidget(defaultWindowPlacementLabel,     1, 0);
00100   manualPlacementGrid->addMultiCellWidget(defaultWindowPlacement, 1, 1, 1, 2, Qt::AlignLeft);
00101   //----------------
00102   //Setup larger boxes in overall grid
00103   mainGrid = new QGridLayout( this, 5, 1, 0);
00104   mainGrid->setSpacing( WIDGET_SPACING );
00105   
00106   mainGrid->addWidget( categoryLabel,       0, 0, Qt::AlignLeft );
00107   mainGrid->addWidget( horizontalLine,      1, 0 );
00108   mainGrid->addWidget( generalSettings,     2, 0 );
00109   mainGrid->addWidget( windowPlacementSize, 3, 0 );
00110   mainGrid->setRowStretch( 4, 1 );
00111 }
00112 //==============================================
00113 void LayoutSettingsWidget::defaultSizeSliderMoved(int v)
00114 {
00115   //update spinbox
00116   defaultWindowSizeValue->setValue( v );
00117 }
00118 //==============================================
00119 void LayoutSettingsWidget::defaultSizeSpinboxChanged(int v)
00120 {
00121   //update slider
00122   defaultWindowSizeSlider->setValue( v );
00123 }
00124 //==============================================
00125 void LayoutSettingsWidget::toggleDefaultSizeEnabled(bool b)
00126 {
00127   sizeFrame->setDisabled(b);
00128 }
00129 //==============================================
00130 void LayoutSettingsWidget::setDefaults(Configuration* config)
00131 {
00132   config->setBool( "layout", "animation", true );
00133   config->setBool( "layout", "showTooltips", true );
00134   config->setBool( "layout", "restoreWindowPlacementSize", true);
00135   //----
00136   QDesktopWidget *desktop = QApplication::desktop();
00137   int width = (8*desktop->width()) / 10;
00138   int height = (8*desktop->height()) / 10;
00139   config->setInt( "layout", "windowWidth", width );
00140   config->setInt( "layout", "windowHeight", height );
00141   config->setInt( "layout", "windowPosX", (desktop->width() - width) / 2 );
00142   config->setInt( "layout", "windowPosY", (desktop->height() - height) / 2 );
00143   //----
00144   config->setInt( "layout", "defaultWindowSize", 80 );
00145   config->setString( "layout", "defaultWindowPlacement", 0 );
00146 }
00147 //==============================================
00148 void LayoutSettingsWidget::loadSettings()
00149 {
00150   useAnimation->setChecked( config->getBool( "layout", "animation" ));
00151   showTooltips->setChecked( config->getBool( "layout", "showTooltips" ));
00152   restoreWindowPlacementSize->setChecked( config->getBool( "layout", "restoreWindowPlacementSize" ));
00153   defaultWindowSizeValue->setValue( config->getInt( "layout", "defaultWindowSize" ));
00154   defaultWindowPlacement->setCurrentItem( config->getInt( "layout", "defaultWindowPlacement" ) );
00155 }
00156 //==============================================
00157 void LayoutSettingsWidget::saveSettings()
00158 {
00159   //set setting values in config object so they are properly saved to disk
00160   config->setBool( "layout", "animation", useAnimation->isChecked() );
00161   config->setBool( "layout", "showTooltips", showTooltips->isChecked() );
00162   config->setBool( "layout", "restoreWindowPlacementSize", restoreWindowPlacementSize->isChecked());
00163   config->setInt( "layout", "defaultWindowSize", defaultWindowSizeValue->value() );
00164   config->setInt( "layout", "defaultWindowPlacement", defaultWindowPlacement->currentItem() );
00165 
00166   //apply setting changes to application behavior
00167   QToolTip::setGloballyEnabled( config->getBool( "layout", "showTooltips" ) );
00168   ((Window*)qApp->mainWidget())->getTitle()->useAnimation( config->getBool( "layout", "animation" ) );
00169 }
00170 //==============================================

Generated on Thu Jan 3 10:54:40 2008 for AlbumShaper by  doxygen 1.5.4