Added donation plug in about box
[easylist] / mainform.cpp
1 #include "mainform.h"\r
2 #include "ui_mainform.h"\r
3 \r
4 MainForm::MainForm(QWidget *parent) :\r
5     QMainWindow(parent),\r
6     ui(new Ui::MainForm)\r
7 {\r
8     ui->setupUi(this);\r
9     settings = new QSettings(WILLEM_LIU, EASY_LIST);\r
10 \r
11     newIndex = 0;\r
12     connect(SystemSettings::getInstance(), SIGNAL(signalKeyboardClosed(bool)), this, SLOT(keyboardClosed(bool)));\r
13 \r
14     ui->actionAuto_Orientation->setChecked(settings->value(AUTO_ORIENTATION).toBool());\r
15     on_actionAuto_Orientation_triggered();\r
16 \r
17     ui->actionSort_A_Z->setChecked(settings->value(SORT_A_Z).toBool());\r
18     on_actionSort_A_Z_triggered();\r
19 \r
20     // Set a default value for CHECKED_ITEMS_TO_BOTTOM\r
21     if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)\r
22     {\r
23         settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);\r
24     }\r
25     ui->actionChecked_bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());\r
26     on_actionChecked_bottom_triggered();\r
27 \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
32     {\r
33         // We use the LANDSCAPE value in the QSettings.\r
34         landscape = settings->value(LANDSCAPE).toBool();\r
35     }\r
36     else\r
37     {\r
38         // Otherwise we set our default into the QSettings.\r
39         settings->setValue(LANDSCAPE, landscape);\r
40     }\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
44     {\r
45         if(SystemSettings::getInstance()->getKeyboardClosed() == false)\r
46         {\r
47             setLandscapeMode(true);\r
48         }\r
49         else\r
50         {\r
51             setLandscapeMode(landscape);\r
52         }\r
53     }\r
54 \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
59 \r
60     connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));\r
61     connect(listForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));\r
62 \r
63     connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));\r
64     connect(editForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));\r
65 \r
66     connect(chooseListForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));\r
67     connect(chooseListForm, SIGNAL(signalNavigate(int)), this, SLOT(changeWidget(int)));\r
68 \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
73 }\r
74 \r
75 MainForm::~MainForm()\r
76 {\r
77     delete ui;\r
78 }\r
79 \r
80 void MainForm::stateOutFinished()\r
81 {\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
87     newWidget->shown();\r
88 }\r
89 \r
90 void MainForm::changeWidget(int step)\r
91 {\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
101     newIndex = step;\r
102     currentWidget->setStateOut();\r
103     qDebug() << "New widget index" << newIndex;\r
104 }\r
105 \r
106 void MainForm::keyboardClosed(bool closed)\r
107 {\r
108     // When keyboard is opened.\r
109     if(ui->actionAuto_Orientation->isChecked() == false)\r
110     {\r
111         if(closed == false)\r
112         {\r
113             setLandscapeMode(true);\r
114         }\r
115         else\r
116         {\r
117             setLandscapeMode(landscape);\r
118         }\r
119     }\r
120 }\r
121 \r
122 void MainForm::setLandscapeMode(bool landscape)\r
123 {\r
124     if(landscape)\r
125     {\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
132 #endif\r
133     }\r
134     else\r
135     {\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
142 #endif\r
143     }\r
144 }\r
145 \r
146 void MainForm::on_actionRotate_triggered()\r
147 {\r
148     qDebug() << "Rotate";\r
149 \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
155 }\r
156 \r
157 void MainForm::on_actionAbout_triggered()\r
158 {\r
159     qDebug() << "About";\r
160     QString aboutText;\r
161     aboutText.append("<html>");\r
162     aboutText.append("EasyList (c) 2010-");\r
163     aboutText.append(QDate::currentDate().toString("yyyy"));\r
164     aboutText.append("<br><br>");\r
165     aboutText.append("Created by Willem Liu.<br>");\r
166     aboutText.append("Created with QtCreator.<br><br>");\r
167     aboutText.append("Please <a href='http://www.willemliu.nl/donate'>donate</a> any amount you deem this app is worthy to keep me going on.<br><br>");\r
168     aboutText.append("</html>");\r
169     QMessageBox::about(this, "EasyList", aboutText);\r
170 }\r
171 \r
172 void MainForm::on_actionChecked_bottom_triggered()\r
173 {\r
174     bool sortToBottom = ui->actionChecked_bottom->isChecked();\r
175     qDebug() << "Checked Bottom" << sortToBottom;\r
176     settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);\r
177     MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);\r
178 }\r
179 \r
180 void MainForm::closeEvent(QCloseEvent *event)\r
181 {\r
182     settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());\r
183     SystemSettings::getInstance()->saveCurrentList();\r
184     event->accept();\r
185 }\r
186 \r
187 void MainForm::on_actionAuto_Orientation_triggered()\r
188 {\r
189     settings->setValue(AUTO_ORIENTATION, ui->actionAuto_Orientation->isChecked());\r
190     qDebug() << "Auto orientation" << ui->actionAuto_Orientation->isChecked();\r
191     if(ui->actionAuto_Orientation->isChecked())\r
192     {\r
193 #ifdef Q_WS_MAEMO_5\r
194         setAttribute(Qt::WA_Maemo5PortraitOrientation, false);\r
195         setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);\r
196         setAttribute(Qt::WA_Maemo5AutoOrientation, true);\r
197 #endif\r
198     }\r
199     else\r
200     {\r
201         setLandscapeMode(landscape);\r
202     }\r
203 }\r
204 \r
205 void MainForm::on_actionSort_A_Z_triggered()\r
206 {\r
207     settings->setValue(SORT_A_Z, ui->actionSort_A_Z->isChecked());\r
208     MyCheckBoxContainer::getInstance()->setSortAlphabetically(ui->actionSort_A_Z->isChecked());\r
209 }\r
210 \r
211 void MainForm::on_actionLists_triggered()\r
212 {\r
213     listForm->saveList();\r
214     changeWidget(2);\r
215 }\r