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
12 connect(SystemSettings::getInstance(), SIGNAL(signalKeyboardClosed(bool)), this, SLOT(keyboardClosed(bool)));
\r
14 ui->actionAuto_Orientation->setChecked(settings->value(AUTO_ORIENTATION).toBool());
\r
15 on_actionAuto_Orientation_triggered();
\r
17 ui->actionSort_A_Z->setChecked(settings->value(SORT_A_Z).toBool());
\r
18 on_actionSort_A_Z_triggered();
\r
20 // Set a default value for CHECKED_ITEMS_TO_BOTTOM
\r
21 if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)
\r
23 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);
\r
25 ui->actionChecked_bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());
\r
26 on_actionChecked_bottom_triggered();
\r
28 // Create a default for landscape mode.
\r
29 landscape = settings->value(LANDSCAPE).toBool();
\r
30 // If LANDSCAPE exists in QSettings.
\r
31 if(settings->contains(LANDSCAPE))
\r
33 // We use the LANDSCAPE value in the QSettings.
\r
34 landscape = settings->value(LANDSCAPE).toBool();
\r
38 // Otherwise we set our default into the QSettings.
\r
39 settings->setValue(LANDSCAPE, landscape);
\r
41 // If keyboard is opened at start. We do landscape mode.
\r
42 // Otherwise we do what's read from the QSettings.
\r
43 if(ui->actionAuto_Orientation->isChecked() == false)
\r
45 if(SystemSettings::getInstance()->getKeyboardClosed() == false)
\r
47 setLandscapeMode(true);
\r
51 setLandscapeMode(landscape);
\r
55 // Populate the QStackedWidget. ListForm is set as the current widget.
\r
56 listForm = new ListForm(this);
\r
57 editForm = new EditForm(this);
\r
58 chooseListForm = new ChooseListForm(this);
\r
60 connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
61 connect(listForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
63 connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
64 connect(editForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
66 connect(chooseListForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
67 connect(chooseListForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
69 ui->stackedWidget->addWidget(listForm);
\r
70 ui->stackedWidget->addWidget(editForm);
\r
71 ui->stackedWidget->addWidget(chooseListForm);
\r
72 ui->stackedWidget->setCurrentWidget(listForm);
\r
75 MainForm::~MainForm()
\r
80 void MainForm::stateOutFinished()
\r
82 qDebug() << "Show new widget" << newIndex;
\r
83 ui->stackedWidget->setCurrentIndex(newIndex);
\r
84 SlideWidget * newWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
85 newWidget->move(0, -newWidget->height());
\r
86 newWidget->setStateIn();
\r
90 void MainForm::changeWidget(int step)
\r
92 SlideWidget * currentWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
93 currentWidget->initStates();
\r
94 int currentIndex = ui->stackedWidget->indexOf(currentWidget);
\r
95 // Because all widgets are started with StateOut as initial state, we
\r
96 // need to reset the current widget to StateIn. The view is showing the
\r
97 // current widget at the place of its StateIn position. But the state
\r
98 // is never set to StateIn.
\r
99 currentWidget->setStateIn();
\r
100 qDebug() << "Current widget index" << currentIndex;
\r
102 currentWidget->setStateOut();
\r
103 qDebug() << "New widget index" << newIndex;
\r
106 void MainForm::keyboardClosed(bool closed)
\r
108 // When keyboard is opened.
\r
109 if(ui->actionAuto_Orientation->isChecked() == false)
\r
111 if(closed == false)
\r
113 setLandscapeMode(true);
\r
117 setLandscapeMode(landscape);
\r
122 void MainForm::setLandscapeMode(bool landscape)
\r
126 tempLandscapeMode = true;
\r
127 qDebug() << LANDSCAPE;
\r
128 #ifdef Q_WS_MAEMO_5
\r
129 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
130 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
131 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
136 tempLandscapeMode = false;
\r
137 qDebug() << PORTRAIT;
\r
138 #ifdef Q_WS_MAEMO_5
\r
139 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
140 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
141 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
146 void MainForm::on_actionRotate_triggered()
\r
148 qDebug() << "Rotate";
\r
150 landscape = (width() < height());
\r
151 settings->setValue(LANDSCAPE, landscape);
\r
152 ui->actionAuto_Orientation->setChecked(false);
\r
153 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
154 setLandscapeMode(landscape);
\r
157 void MainForm::on_actionAbout_triggered()
\r
159 qDebug() << "About";
\r
161 aboutText.append("EasyList (c) 2010\n\n");
\r
162 aboutText.append("Created by Willem Liu.\n");
\r
163 aboutText.append("Created with QtCreator.\n");
\r
164 QMessageBox::about(this, "EasyList", aboutText);
\r
167 void MainForm::on_actionChecked_bottom_triggered()
\r
169 bool sortToBottom = ui->actionChecked_bottom->isChecked();
\r
170 qDebug() << "Checked Bottom" << sortToBottom;
\r
171 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);
\r
172 MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);
\r
175 void MainForm::closeEvent(QCloseEvent *event)
\r
177 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
178 SystemSettings::getInstance()->saveCurrentList();
\r
182 void MainForm::on_actionAuto_Orientation_triggered()
\r
184 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
185 qDebug() << "Auto orientation" << ui->actionAuto_Orientation->isChecked();
\r
186 if(ui->actionAuto_Orientation->isChecked())
\r
188 #ifdef Q_WS_MAEMO_5
\r
189 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
190 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
191 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
\r
196 setLandscapeMode(landscape);
\r
200 void MainForm::on_actionSort_A_Z_triggered()
\r
202 settings->setValue(SORT_A_Z, ui->actionSort_A_Z->isChecked());
\r
203 MyCheckBoxContainer::getInstance()->setSortAlphabetically(ui->actionSort_A_Z->isChecked());
\r
206 void MainForm::on_actionLists_triggered()
\r
208 listForm->saveList();
\r