1 #include "mainform.h"
\r
2 #include "ui_mainform.h"
\r
4 MainForm::MainForm(QWidget *parent) :
\r
9 settings = new QSettings(WILLEM_LIU, EASY_LIST);
\r
13 connect(SystemSettings::getInstance(), SIGNAL(signalKeyboardClosed(bool)), this, SLOT(keyboardClosed(bool)));
\r
15 ui->actionAuto_Orientation->setChecked(settings->value(AUTO_ORIENTATION).toBool());
\r
16 on_actionAuto_Orientation_triggered();
\r
18 ui->actionSort_A_Z->setChecked(settings->value(SORT_A_Z).toBool());
\r
19 on_actionSort_A_Z_triggered();
\r
21 // Set a default value for CHECKED_ITEMS_TO_BOTTOM
\r
22 if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)
\r
24 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);
\r
26 ui->actionChecked_bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());
\r
27 on_actionChecked_bottom_triggered();
\r
29 // Create a default for landscape mode.
\r
30 landscape = settings->value(LANDSCAPE).toBool();
\r
31 // If LANDSCAPE exists in QSettings.
\r
32 if(settings->contains(LANDSCAPE))
\r
34 // We use the LANDSCAPE value in the QSettings.
\r
35 landscape = settings->value(LANDSCAPE).toBool();
\r
39 // Otherwise we set our default into the QSettings.
\r
40 settings->setValue(LANDSCAPE, landscape);
\r
42 // If keyboard is opened at start. We do landscape mode.
\r
43 // Otherwise we do what's read from the QSettings.
\r
44 if(ui->actionAuto_Orientation->isChecked() == false)
\r
46 if(SystemSettings::getInstance()->getKeyboardClosed() == false)
\r
48 setLandscapeMode(true);
\r
52 setLandscapeMode(landscape);
\r
56 // Populate the QStackedWidget. ListForm is set as the current widget.
\r
57 listForm = new ListForm(this);
\r
58 editForm = new EditForm(this);
\r
60 connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
61 connect(listForm, SIGNAL(signalEditListPushButtonTriggered(SlideWidget*)), this, SLOT(changeWidget(SlideWidget*)));
\r
63 connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
64 connect(editForm, SIGNAL(signalCancelPushButtonClicked(SlideWidget*)), this, SLOT(changeWidget(SlideWidget*)));
\r
65 connect(editForm, SIGNAL(signalSavePushButtonClicked(SlideWidget*)), this, SLOT(changeWidget(SlideWidget*)));
\r
67 ui->stackedWidget->addWidget(listForm);
\r
68 ui->stackedWidget->addWidget(editForm);
\r
69 ui->stackedWidget->setCurrentWidget(listForm);
\r
72 MainForm::~MainForm()
\r
77 void MainForm::stateOutFinished()
\r
79 qDebug() << "Show new widget" << newIndex;
\r
80 ui->stackedWidget->setCurrentIndex(newIndex);
\r
81 SlideWidget * newWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
82 newWidget->move(0, -newWidget->height());
\r
83 newWidget->setStateIn();
\r
87 void MainForm::changeWidget(SlideWidget * currentWidget)
\r
89 currentWidget->initStates();
\r
90 int currentIndex = ui->stackedWidget->indexOf(currentWidget);
\r
91 // Because all widgets are started with StateOut as initial state, we
\r
92 // need to reset the current widget to StateIn. The view is showing the
\r
93 // current widget at the place of its StateIn position. But the state
\r
94 // is never set to StateIn.
\r
95 currentWidget->setStateIn();
\r
96 qDebug() << "Current widget index" << currentIndex;
\r
97 if(currentIndex < ui->stackedWidget->count()-1)
\r
99 newIndex = currentIndex+1;
\r
100 currentWidget->setStateOut();
\r
104 if(ui->stackedWidget->count() > 0)
\r
107 currentWidget->setStateOut();
\r
111 qDebug() << "StackedWidget does not have any widgets";
\r
114 qDebug() << "New widget index" << newIndex;
\r
117 void MainForm::keyboardClosed(bool closed)
\r
119 // When keyboard is opened.
\r
120 if(ui->actionAuto_Orientation->isChecked() == false)
\r
122 if(closed == false)
\r
124 setLandscapeMode(true);
\r
128 setLandscapeMode(landscape);
\r
133 void MainForm::setLandscapeMode(bool landscape)
\r
137 tempLandscapeMode = true;
\r
138 qDebug() << LANDSCAPE;
\r
139 #ifdef Q_WS_MAEMO_5
\r
140 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
141 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
142 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
147 tempLandscapeMode = false;
\r
148 qDebug() << PORTRAIT;
\r
149 #ifdef Q_WS_MAEMO_5
\r
150 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
151 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
152 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
157 void MainForm::on_actionRotate_triggered()
\r
159 qDebug() << "Rotate";
\r
161 landscape = (width() < height());
\r
162 settings->setValue(LANDSCAPE, landscape);
\r
163 ui->actionAuto_Orientation->setChecked(false);
\r
164 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
165 setLandscapeMode(landscape);
\r
168 void MainForm::on_actionAbout_triggered()
\r
170 qDebug() << "About";
\r
172 aboutText.append("EasyList (c) 2010\n\n");
\r
173 aboutText.append("Created by Willem Liu.\n");
\r
174 aboutText.append("Created with QtCreator.\n");
\r
175 QMessageBox::about(this, "EasyList", aboutText);
\r
178 void MainForm::on_actionChecked_bottom_triggered()
\r
180 bool sortToBottom = ui->actionChecked_bottom->isChecked();
\r
181 qDebug() << "Checked Bottom" << sortToBottom;
\r
182 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);
\r
183 MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);
\r
186 void MainForm::closeEvent(QCloseEvent *event)
\r
188 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
192 void MainForm::on_actionAuto_Orientation_triggered()
\r
194 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
195 qDebug() << "Auto orientation" << ui->actionAuto_Orientation->isChecked();
\r
196 if(ui->actionAuto_Orientation->isChecked())
\r
198 #ifdef Q_WS_MAEMO_5
\r
199 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
200 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
201 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
\r
206 setLandscapeMode(landscape);
\r
210 void MainForm::on_actionSort_A_Z_triggered()
\r
212 settings->setValue(SORT_A_Z, ui->actionSort_A_Z->isChecked());
\r
213 MyCheckBoxContainer::getInstance()->setSortAlphabetically(ui->actionSort_A_Z->isChecked());
\r