AlbumShaper  1.0a3
configurationWidget.cpp
Go to the documentation of this file.
1 //==============================================
2 // copyright : (C) 2003-2005 by Will Stokes
3 //==============================================
4 // This program is free software; you can redistribute it
5 // and/or modify it under the terms of the GNU General
6 // Public License as published by the Free Software
7 // Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //==============================================
10 
11 //Systemwide includes
12 #include <qwidget.h>
13 #include <qlayout.h>
14 #include <qpixmap.h>
15 #include <qapplication.h>
16 #include <qtooltip.h>
17 #include <qpushbutton.h>
18 //Added by qt3to4:
19 #include <Q3GridLayout>
20 #include <Q3Frame>
21 #include <QCloseEvent>
22 
23 //Projectwide includes
24 #include "configuration.h"
25 #include "configurationWidget.h"
26 #include "groupsWidget.h"
27 #include "groupIcon.h"
28 #include "layoutSettingsWidget.h"
29 #include "loadingSavingWidget.h"
30 #include "alertsWidget.h"
31 #include "../config.h"
32 
33 //==============================================
35  QWidget *parent,
36  const char* name ) :
37  QDialog(parent,name)
38 {
39  //store config pointer
40  this->config = config;
41  //--
42  //set window title
43  setCaption( tr("Settings"));
44  //--
45  //no icon currently hovered over
47  //----------------------------------------------
48  //create settings widget
49  layoutWidget = new LayoutSettingsWidget(config, this);
50  loadingSavingWidget = new LoadingSavingWidget(config, this);
51  alertsWidget = new AlertsWidget( config, this );
52  //----------------------------------------------
53  //create iconview and icons for groups
54  groups = new GroupsWidget( this );
55  groups->setItemTextPos( Q3IconView::Right );
56 // groups->setMaxItemWidth(20);
57  //----
58  //construct group labels
59  QString labels[3];
60  labels[0] = tr("Appearance");
61  labels[1] = tr("Load/Save");
62  labels[2] = tr("Alerts");
63  //----
64  //find max text width
65  int maxLabelWidth = 0;
66  int i;
67  QFontMetrics fm( qApp->font() );
68  for(i=0; i<3; i++)
69  {
70  if( fm.width( labels[i] ) > maxLabelWidth )
71  maxLabelWidth = fm.width( labels[i] );
72  }
73  groups->setTextWidth( maxLabelWidth );
74  //----
75  //construct actual group icons
76  layoutIcon = new GroupIcon( groups, QPixmap(QString(IMAGE_PATH)+"settingsIcons/layout.png" ),
77  labels[0], layoutWidget );
78  layoutIcon->setDragEnabled(false);
79  //----
80  loadingSavingIcon = new GroupIcon( groups, QPixmap(QString(IMAGE_PATH)+"settingsIcons/loadsave.png" ),
81  labels[1], loadingSavingWidget );
82  loadingSavingIcon->setDragEnabled(false);
83  //----
84  alertsIcon = new GroupIcon( groups, QPixmap(QString(IMAGE_PATH)+"settingsIcons/alerts.png" ),
85  labels[2], alertsWidget );
86  alertsIcon->setDragEnabled(false);
87  //-------------------------
88  //set default selection
90  layoutIcon->setSelected(true);
91  loadingSavingWidget->hide();
92  alertsWidget->hide();
93  //-------------------------
94  //connect selectionChanged signal to update which settings dialog is displayed
95  connect( groups, SIGNAL(selectionChanged(Q3IconViewItem*)),
97 
98  //connect mouse over events to paint pseudo selection in ligher blue
99  connect( groups, SIGNAL(onItem(Q3IconViewItem*)),
100  SLOT(repaintGroup(Q3IconViewItem*)) );
101 
102  //clear any pseudo selection when mouse moves off icons
103  connect( groups, SIGNAL(onViewport()),
104  SLOT(clearPseudoSelection()) );
105 
106 
107  //create buttons frame and widgets
108  buttonsFrame = new Q3Frame( this );
109  okButton = new QPushButton( tr("Apply"), buttonsFrame );
110  okButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
111  okButton->setDefault(true);
112  connect( okButton, SIGNAL(clicked()), SLOT(saveSettings()) );
113  cancelButton = new QPushButton( tr("Cancel"), buttonsFrame );
114  cancelButton->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
115  connect( cancelButton, SIGNAL(clicked()), SLOT(reject()) );
116  buttonsGrid = new Q3GridLayout( buttonsFrame, 1, 5, 0 );
117  buttonsGrid->setColStretch( 0, 1 );
118  buttonsGrid->addWidget( okButton, 0, 1 );
119  buttonsGrid->addColSpacing( 2, 10 );
120  buttonsGrid->addWidget( cancelButton, 0, 3 );
121  buttonsGrid->setColStretch( 4, 1 );
122  //----------------------------------------------
123  //place all widgets in a grid
124  grid = new Q3GridLayout( this, 5, 5, 0 );
125 
126  grid->setRowSpacing(0,8);
127 
128  grid->addWidget( groups, 1, 1);
129  grid->addWidget( alertsWidget, 1, 3);
130  grid->addWidget( layoutWidget, 1, 3);
131  grid->addWidget( loadingSavingWidget, 1, 3);
132  grid->setRowStretch( 1, 1 );
133  grid->setColStretch( 3, 1 );
134 
135  grid->setRowSpacing(2,8);
136 
137  grid->addMultiCellWidget( buttonsFrame, 3, 3, 0, 4);
138 
139  grid->setRowSpacing(4,8);
140 
141  grid->setColSpacing(0,8);
142  grid->setColSpacing(2,8);
143  grid->setColSpacing(4,8);
144 
145  groups->setGridX(1);
146  groups->arrangeItemsInGrid();
147 
148  int maxWidth = 0;
149  int maxHeight = 0;
150 
151  layoutWidget->constPolish();
152  loadingSavingWidget->constPolish();
153  alertsWidget->constPolish();
154  groups->constPolish();
155 
156  QSize s = layoutWidget->minimumSizeHint();
157  if(maxWidth < s.width()) maxWidth = s.width();
158  if(maxHeight < s.height()) maxHeight = s.height();
159 
160  s = loadingSavingWidget->minimumSizeHint();
161  if(maxWidth < s.width()) maxWidth = s.width();
162  if(maxHeight < s.height()) maxHeight = s.height();
163 
164  s = alertsWidget->minimumSizeHint();
165  if(maxWidth < s.width()) maxWidth = s.width();
166  if(maxHeight < s.height()) maxHeight = s.height();
167 
168  s = groups->minimumSizeHint();
169  if(maxHeight < s.height()) maxHeight = s.height();
170 
171  maxWidth = maxWidth + s.width();
172  maxHeight += okButton->minimumSizeHint().height();
173  //add padding
174  maxWidth += 3*8;
175  maxHeight += 3*8;
176 
177  //add a little extra for when text entries need more space
178  maxWidth += 100;
179 
180  resize( maxWidth, maxHeight );
181 
182  show();
183  setFixedSize(size());
184  //----------------------------------------------
185  //load setting values
189  //----------------------------------------------
190 }
191 //==============================================
193 {
194  //hide current selection
195  currentSettingsWidget->hide();
196 
197  //set current and show
198  currentSettingsWidget = ((GroupIcon*)selection)->getSettingsWidget();
199  currentSettingsWidget->show();
200 }
201 //==============================================
203 {
204  //if old pseudo selection unselect it
206 
207  //paint new selection
208  currentPseudoSelection = (GroupIcon*)pseudoSelection;
210  groups->repaintItem(currentPseudoSelection);
211 }
212 //==============================================
214 {
215  //if old pseudo selection unselect it
216  if(currentPseudoSelection != NULL)
217  {
219  groups->repaintItem(currentPseudoSelection);
220  currentPseudoSelection = NULL;
221  }
222 }
223 //==============================================
225 {
229  close();
230 }
231 //==============================================
232 void ConfigurationWidget::closeEvent( QCloseEvent* e)
233 {
234  QWidget::closeEvent( e );
235  emit closed();
236 }
237 //==============================================
239 {
240  QDialog::reject();
241  emit closed();
242 }
243 //==============================================
QPushButton * cancelButton
Displays group icon and text, also contains pointer to widget for setting group settings.
Definition: groupIcon.h:30
GroupIcon * currentPseudoSelection
LayoutSettingsWidget * layoutWidget
void loadSettings()
Q3GridLayout * grid
Grid widgets place in.
QString IMAGE_PATH
Definition: config.cpp:18
ConfigurationWidget(Configuration *config, QWidget *parent=0, const char *name=0)
Displays group icon and text, also contains pointer to widget for setting group settings.
Definition: groupsWidget.h:28
void setMousedOver(bool val)
Definition: groupIcon.cpp:72
void clearPseudoSelection()
clears any pseudo selections
void closeEvent(QCloseEvent *e)
AlertsWidget * alertsWidget
GroupsWidget * groups
list of subalbums
Configuration object manages all user-specific application settings.
Definition: configuration.h:24
GroupIcon * alertsIcon
settings icons
void updateDialogue(Q3IconViewItem *selection)
updates shown settings dialogue based on newly selected group
Loading/Saving Settings.
Alerts Settings.
Definition: alertsWidget.h:34
LoadingSavingWidget * loadingSavingWidget
settings widgets
Q3GridLayout * buttonsGrid
void setTextWidth(int val)
void saveSettings()
void repaintGroup(Q3IconViewItem *pseudoSelection)
repaints a group icon if move is moved over it
Configuration * config
Backend config object pointer.