AlbumShaper
1.0a3
|
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 <qwidget.h> 00013 #include <qlayout.h> 00014 #include <qpixmap.h> 00015 #include <qapplication.h> 00016 #include <qtooltip.h> 00017 #include <qpushbutton.h> 00018 00019 //Projectwide includes 00020 #include "configuration.h" 00021 #include "configurationWidget.h" 00022 #include "groupsWidget.h" 00023 #include "groupIcon.h" 00024 #include "layoutSettingsWidget.h" 00025 #include "loadingSavingWidget.h" 00026 #include "alertsWidget.h" 00027 #include "../config.h" 00028 00029 //============================================== 00030 ConfigurationWidget::ConfigurationWidget(Configuration* config, 00031 QWidget *parent, 00032 const char* name ) : 00033 QDialog(parent,name) 00034 { 00035 //store config pointer 00036 this->config = config; 00037 //-- 00038 //set window title 00039 setCaption( tr("Settings")); 00040 //-- 00041 //no icon currently hovered over 00042 currentPseudoSelection = NULL; 00043 //---------------------------------------------- 00044 //create settings widget 00045 layoutWidget = new LayoutSettingsWidget(config, this); 00046 loadingSavingWidget = new LoadingSavingWidget(config, this); 00047 alertsWidget = new AlertsWidget( config, this ); 00048 //---------------------------------------------- 00049 //create iconview and icons for groups 00050 groups = new GroupsWidget( this ); 00051 groups->setItemTextPos( QIconView::Right ); 00052 // groups->setMaxItemWidth(20); 00053 //---- 00054 //construct group labels 00055 QString labels[3]; 00056 labels[0] = tr("Appearance"); 00057 labels[1] = tr("Load/Save"); 00058 labels[2] = tr("Alerts"); 00059 //---- 00060 //find max text width 00061 int maxLabelWidth = 0; 00062 int i; 00063 QFontMetrics fm( qApp->font() ); 00064 for(i=0; i<3; i++) 00065 { 00066 if( fm.width( labels[i] ) > maxLabelWidth ) 00067 maxLabelWidth = fm.width( labels[i] ); 00068 } 00069 groups->setTextWidth( maxLabelWidth ); 00070 //---- 00071 //construct actual group icons 00072 layoutIcon = new GroupIcon( groups, QPixmap(QString(IMAGE_PATH)+"settingsIcons/layout.png" ), 00073 labels[0], layoutWidget ); 00074 layoutIcon->setDragEnabled(false); 00075 //---- 00076 loadingSavingIcon = new GroupIcon( groups, QPixmap(QString(IMAGE_PATH)+"settingsIcons/loadsave.png" ), 00077 labels[1], loadingSavingWidget ); 00078 loadingSavingIcon->setDragEnabled(false); 00079 //---- 00080 alertsIcon = new GroupIcon( groups, QPixmap(QString(IMAGE_PATH)+"settingsIcons/alerts.png" ), 00081 labels[2], alertsWidget ); 00082 alertsIcon->setDragEnabled(false); 00083 //------------------------- 00084 //set default selection 00085 currentSettingsWidget = layoutWidget; 00086 layoutIcon->setSelected(true); 00087 loadingSavingWidget->hide(); 00088 alertsWidget->hide(); 00089 //------------------------- 00090 //connect selectionChanged signal to update which settings dialog is displayed 00091 connect( groups, SIGNAL(selectionChanged(QIconViewItem*)), 00092 SLOT(updateDialogue(QIconViewItem*)) ); 00093 00094 //connect mouse over events to paint pseudo selection in ligher blue 00095 connect( groups, SIGNAL(onItem(QIconViewItem*)), 00096 SLOT(repaintGroup(QIconViewItem*)) ); 00097 00098 //clear any pseudo selection when mouse moves off icons 00099 connect( groups, SIGNAL(onViewport()), 00100 SLOT(clearPseudoSelection()) ); 00101 00102 00103 //create buttons frame and widgets 00104 buttonsFrame = new QFrame( this ); 00105 okButton = new QPushButton( tr("Apply"), buttonsFrame ); 00106 okButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); 00107 okButton->setDefault(true); 00108 connect( okButton, SIGNAL(clicked()), SLOT(saveSettings()) ); 00109 cancelButton = new QPushButton( tr("Cancel"), buttonsFrame ); 00110 cancelButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); 00111 connect( cancelButton, SIGNAL(clicked()), SLOT(reject()) ); 00112 buttonsGrid = new QGridLayout( buttonsFrame, 1, 5, 0 ); 00113 buttonsGrid->setColStretch( 0, 1 ); 00114 buttonsGrid->addWidget( okButton, 0, 1 ); 00115 buttonsGrid->addColSpacing( 2, 10 ); 00116 buttonsGrid->addWidget( cancelButton, 0, 3 ); 00117 buttonsGrid->setColStretch( 4, 1 ); 00118 //---------------------------------------------- 00119 //place all widgets in a grid 00120 grid = new QGridLayout( this, 5, 5, 0 ); 00121 00122 grid->setRowSpacing(0,8); 00123 00124 grid->addWidget( groups, 1, 1); 00125 grid->addWidget( alertsWidget, 1, 3); 00126 grid->addWidget( layoutWidget, 1, 3); 00127 grid->addWidget( loadingSavingWidget, 1, 3); 00128 grid->setRowStretch( 1, 1 ); 00129 grid->setColStretch( 3, 1 ); 00130 00131 grid->setRowSpacing(2,8); 00132 00133 grid->addMultiCellWidget( buttonsFrame, 3, 3, 0, 4); 00134 00135 grid->setRowSpacing(4,8); 00136 00137 grid->setColSpacing(0,8); 00138 grid->setColSpacing(2,8); 00139 grid->setColSpacing(4,8); 00140 00141 groups->setGridX(1); 00142 groups->arrangeItemsInGrid(); 00143 00144 int maxWidth = 0; 00145 int maxHeight = 0; 00146 00147 layoutWidget->constPolish(); 00148 loadingSavingWidget->constPolish(); 00149 alertsWidget->constPolish(); 00150 groups->constPolish(); 00151 00152 QSize s = layoutWidget->minimumSizeHint(); 00153 if(maxWidth < s.width()) maxWidth = s.width(); 00154 if(maxHeight < s.height()) maxHeight = s.height(); 00155 00156 s = loadingSavingWidget->minimumSizeHint(); 00157 if(maxWidth < s.width()) maxWidth = s.width(); 00158 if(maxHeight < s.height()) maxHeight = s.height(); 00159 00160 s = alertsWidget->minimumSizeHint(); 00161 if(maxWidth < s.width()) maxWidth = s.width(); 00162 if(maxHeight < s.height()) maxHeight = s.height(); 00163 00164 s = groups->minimumSizeHint(); 00165 if(maxHeight < s.height()) maxHeight = s.height(); 00166 00167 maxWidth = maxWidth + s.width(); 00168 maxHeight += okButton->minimumSizeHint().height(); 00169 //add padding 00170 maxWidth += 3*8; 00171 maxHeight += 3*8; 00172 00173 //add a little extra for when text entries need more space 00174 maxWidth += 100; 00175 00176 resize( maxWidth, maxHeight ); 00177 00178 show(); 00179 setFixedSize(size()); 00180 //---------------------------------------------- 00181 //load setting values 00182 layoutWidget->loadSettings(); 00183 loadingSavingWidget->loadSettings(); 00184 alertsWidget->loadSettings(); 00185 //---------------------------------------------- 00186 } 00187 //============================================== 00188 void ConfigurationWidget::updateDialogue( QIconViewItem* selection) 00189 { 00190 //hide current selection 00191 currentSettingsWidget->hide(); 00192 00193 //set current and show 00194 currentSettingsWidget = ((GroupIcon*)selection)->getSettingsWidget(); 00195 currentSettingsWidget->show(); 00196 } 00197 //============================================== 00198 void ConfigurationWidget::repaintGroup( QIconViewItem* pseudoSelection) 00199 { 00200 //if old pseudo selection unselect it 00201 clearPseudoSelection(); 00202 00203 //paint new selection 00204 currentPseudoSelection = (GroupIcon*)pseudoSelection; 00205 currentPseudoSelection->setMousedOver(true); 00206 groups->repaintItem(currentPseudoSelection); 00207 } 00208 //============================================== 00209 void ConfigurationWidget::clearPseudoSelection() 00210 { 00211 //if old pseudo selection unselect it 00212 if(currentPseudoSelection != NULL) 00213 { 00214 currentPseudoSelection->setMousedOver(false); 00215 groups->repaintItem(currentPseudoSelection); 00216 currentPseudoSelection = NULL; 00217 } 00218 } 00219 //============================================== 00220 void ConfigurationWidget::saveSettings() 00221 { 00222 layoutWidget->saveSettings(); 00223 loadingSavingWidget->saveSettings(); 00224 alertsWidget->saveSettings(); 00225 close(); 00226 } 00227 //============================================== 00228 void ConfigurationWidget::closeEvent( QCloseEvent* e) 00229 { 00230 QWidget::closeEvent( e ); 00231 emit closed(); 00232 } 00233 //============================================== 00234 void ConfigurationWidget::reject() 00235 { 00236 QDialog::reject(); 00237 emit closed(); 00238 } 00239 //==============================================