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
59 chooseListForm = new ChooseListForm(this);
\r
61 connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
62 connect(listForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
64 connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
65 connect(editForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
67 connect(chooseListForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
68 connect(chooseListForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));
\r
70 ui->stackedWidget->addWidget(listForm);
\r
71 ui->stackedWidget->addWidget(editForm);
\r
72 ui->stackedWidget->addWidget(chooseListForm);
\r
73 ui->stackedWidget->setCurrentWidget(listForm);
\r
76 MainForm::~MainForm()
\r
81 void MainForm::stateOutFinished()
\r
83 qDebug() << "Show new widget" << newIndex;
\r
84 ui->stackedWidget->setCurrentIndex(newIndex);
\r
85 SlideWidget * newWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
86 newWidget->move(0, -newWidget->height());
\r
87 newWidget->setStateIn();
\r
91 void MainForm::changeWidget(int step)
\r
93 SlideWidget * currentWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
94 currentWidget->initStates();
\r
95 int currentIndex = ui->stackedWidget->indexOf(currentWidget);
\r
96 // Because all widgets are started with StateOut as initial state, we
\r
97 // need to reset the current widget to StateIn. The view is showing the
\r
98 // current widget at the place of its StateIn position. But the state
\r
99 // is never set to StateIn.
\r
100 currentWidget->setStateIn();
\r
101 qDebug() << "Current widget index" << currentIndex;
\r
103 currentWidget->setStateOut();
\r
104 qDebug() << "New widget index" << newIndex;
\r
107 void MainForm::keyboardClosed(bool closed)
\r
109 // When keyboard is opened.
\r
110 if(ui->actionAuto_Orientation->isChecked() == false)
\r
112 if(closed == false)
\r
114 setLandscapeMode(true);
\r
118 setLandscapeMode(landscape);
\r
123 void MainForm::setLandscapeMode(bool landscape)
\r
127 tempLandscapeMode = true;
\r
128 qDebug() << LANDSCAPE;
\r
129 #ifdef Q_WS_MAEMO_5
\r
130 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
131 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
132 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
137 tempLandscapeMode = false;
\r
138 qDebug() << PORTRAIT;
\r
139 #ifdef Q_WS_MAEMO_5
\r
140 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
141 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
142 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
147 void MainForm::on_actionRotate_triggered()
\r
149 qDebug() << "Rotate";
\r
151 landscape = (width() < height());
\r
152 settings->setValue(LANDSCAPE, landscape);
\r
153 ui->actionAuto_Orientation->setChecked(false);
\r
154 settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());
\r
155 setLandscapeMode(landscape);
\r
158 void MainForm::on_actionAbout_triggered()
\r
160 qDebug() << "About";
\r
162 aboutText.append("EasyList (c) 2010\n\n");
\r
163 aboutText.append("Created by Willem Liu.\n");
\r
164 aboutText.append("Created with QtCreator.\n");
\r
165 QMessageBox::about(this, "EasyList", aboutText);
\r
168 void MainForm::on_actionChecked_bottom_triggered()
\r
170 bool sortToBottom = ui->actionChecked_bottom->isChecked();
\r
171 qDebug() << "Checked Bottom" << sortToBottom;
\r
172 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);
\r
173 MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);
\r
176 void MainForm::closeEvent(QCloseEvent *event)
\r
178 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\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