#include "ui_mainwindow.h"\r
#include "ui_listwindow.h"\r
\r
-#define DBUS_KEYBOARD_SLIDE "/org/freedesktop/Hal/devices/platform_slide"\r
-\r
/**\r
* Constructor.\r
* Settings are initialised here.\r
QString("PropertyModified"),\r
this, SLOT(slotKeyboardSlide()));\r
// Initialise the settings.\r
- settings = new QSettings("WillemLiu", "easylist");\r
+ settings = new QSettings(WILLEM_LIU, EASY_LIST);\r
+\r
+ // Set a default value for CHECKED_ITEMS_TO_BOTTOM\r
+ if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)\r
+ {\r
+ settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);\r
+ }\r
+\r
// We always start in landscape mode.\r
- landscape = settings->value("Landscape").toBool();\r
- if(settings->contains("Landscape"))\r
+ landscape = settings->value(LANDSCAPE).toBool();\r
+ if(settings->contains(LANDSCAPE))\r
{\r
- landscape = settings->value("Landscape").toBool();\r
+ landscape = settings->value(LANDSCAPE).toBool();\r
}\r
- settings->setValue("Landscape", landscape);\r
- // If keyboard is opened at start.\r
+ settings->setValue(LANDSCAPE, landscape);\r
+ // If keyboard is opened at start. We do landscape mode.\r
+ // Otherwise we do what's read from the QSettings.\r
if(isKeyboardClosed() == false)\r
{\r
- landscape = true;\r
+ setLandscapeMode(true);\r
+ }\r
+ else\r
+ {\r
+ setLandscapeMode(landscape);\r
}\r
- setLandscapeMode(landscape);\r
// Auto-detect portrait/landscape mode. Only works on top widget.\r
// setAttribute(Qt::WA_Maemo5AutoOrientation, true);\r
+\r
showListWindow();\r
}\r
\r
void MainWindow::slotKeyboardSlide()\r
{\r
// When keyboard is opened.\r
- if(false == isKeyboardClosed())\r
+ if(isKeyboardClosed() == false)\r
{\r
setLandscapeMode(true);\r
}\r
void MainWindow::slotEditWindowSave()\r
{\r
qDebug() << "Save";\r
- settings->setValue("ListText", editUi->textEdit->toPlainText());\r
+ settings->setValue(LIST_TEXT, editUi->textEdit->toPlainText());\r
showListWindow();\r
}\r
\r
/**\r
* Slot for action from Clear selected button in de the list window.\r
+ * It clears all QCheckBoxes from the layout, removes all checked items from\r
+ * the list text and finally calls generateList().\r
*\r
* @fn slotListWindowClearSelected\r
*/\r
}\r
}\r
\r
- settings->setValue("ListText", listText);\r
+ settings->setValue(LIST_TEXT, listText);\r
generateList();\r
}\r
\r
/**\r
+ * Prefix all checked items with ! in the list text and save it to QSettings.\r
+ */\r
+void MainWindow::slotListWindowSaveChecked()\r
+{\r
+ qDebug() << "Save selected";\r
+ QString listText("");\r
+ foreach(QCheckBox * cb, checkBoxes)\r
+ {\r
+ QString item(cb->text());\r
+ if(cb->isChecked() == true)\r
+ {\r
+ if(item.startsWith("!") == false)\r
+ {\r
+ item.push_front("!");\r
+ }\r
+ listText.append(item);\r
+ }\r
+ else\r
+ {\r
+ if(item.startsWith("!") == true)\r
+ {\r
+ item = item.replace("!", "");\r
+ }\r
+ listText.append(item);\r
+ }\r
+ listText.append("\n");\r
+ }\r
+\r
+ settings->setValue(LIST_TEXT, listText);\r
+}\r
+\r
+/**\r
+ * Is called when a checkbox has been clicked.\r
+ *\r
+ * @fn slotActionCheckBox\r
+ * @param bool checked - true if checkbox is checked.\r
+ */\r
+void MainWindow::slotActionCheckBox(bool checked)\r
+{\r
+ qDebug() << "CheckBox checked=" << checked;\r
+ slotListWindowSaveChecked();\r
+ if(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool())\r
+ {\r
+ slotSortCheckedBottom();\r
+ // Remove all the checkboxes from the screen.\r
+ foreach(QCheckBox * cb, checkBoxes)\r
+ {\r
+ cb->deleteLater();\r
+ }\r
+ generateList();\r
+ }\r
+ else\r
+ {\r
+ qDebug() << "No need to sort items to bottom";\r
+ }\r
+}\r
+\r
+/**\r
+ * Sort checked items to bottom of the list text and returns the new list text.\r
+ *\r
+ * @fn slotSortCheckedBottom\r
+ *\r
+ * @return QString - the new list text.\r
+ */\r
+QString MainWindow::slotSortCheckedBottom()\r
+{\r
+ QString result(settings->value(LIST_TEXT).toString());\r
+ if(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool())\r
+ {\r
+ QStringList list = result.split("\n");\r
+ QString listText("");\r
+ QString checkedListText("");\r
+ foreach(QString item, list)\r
+ {\r
+ if(item.length() > 0)\r
+ {\r
+ if(item.startsWith("!"))\r
+ {\r
+ checkedListText.append(item);\r
+ checkedListText.append("\n");\r
+ }\r
+ else\r
+ {\r
+ listText.append(item);\r
+ listText.append("\n");\r
+ }\r
+ }\r
+ }\r
+ listText.append(checkedListText);\r
+ qDebug() << "Sort checked items to bottom";\r
+ settings->setValue(LIST_TEXT, listText);\r
+ result = listText;\r
+ }\r
+ return result;\r
+}\r
+\r
+/**\r
* Show the edit window.\r
*\r
* @fn showEditWindow\r
*/\r
void MainWindow::showEditWindow()\r
{\r
+ slotListWindowSaveChecked();\r
editUi->setupUi(this);\r
- editUi->textEdit->setText(settings->value("ListText").toString());\r
+ editUi->textEdit->setText(settings->value(LIST_TEXT).toString());\r
connect(editUi->savePushButton, SIGNAL(clicked()), this, SLOT(slotEditWindowSave()));\r
connect(editUi->cancelPushButton, SIGNAL(clicked()), this, SLOT(slotEditWindowCancel()));\r
}\r
{\r
listUi->setupUi(this);\r
listUi->listVerticalLayout->setAlignment(Qt::AlignTop);\r
+ listUi->actionChecked_Bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());\r
+ slotSortCheckedBottom();\r
generateList();\r
connect(listUi->editListPushButton, SIGNAL(clicked()), this, SLOT(slotListWindowEdit()));\r
connect(listUi->clearSelectedPushButton, SIGNAL(clicked()), this, SLOT(slotListWindowClearSelected()));\r
+ connect(listUi->menuChecked_Bottom, SIGNAL(triggered(QAction*)), this, SLOT(slotActionCheckedBottom(QAction*)));\r
connect(listUi->menuAbout, SIGNAL(triggered(QAction*)), this, SLOT(slotActionAbout(QAction*)));\r
connect(listUi->menuRotate, SIGNAL(triggered(QAction*)), this, SLOT(slotActionRotate(QAction*)));\r
}\r
qDebug() << "Generate List";\r
\r
checkBoxes.clear();\r
- QString text = settings->value("ListText").toString();\r
+ QString text = settings->value(LIST_TEXT).toString();\r
QStringList list = text.split("\n");\r
\r
foreach(QString item, list)\r
if(item.length() > 0)\r
{\r
QCheckBox * cb = new QCheckBox(item);\r
+ connect(cb, SIGNAL(clicked(bool)), this, SLOT(slotActionCheckBox(bool)));\r
+ if(item.startsWith("!"))\r
+ {\r
+ QString itemName(item.right(item.length()-1));\r
+ cb->setText(itemName);\r
+ cb->setChecked(true);\r
+ }\r
checkBoxes.append(cb);\r
listUi->listVerticalLayout->addWidget(cb);\r
}\r
void MainWindow::closeEvent(QCloseEvent *event)\r
{\r
qDebug() << "Closed";\r
+ slotListWindowSaveChecked();\r
event->accept();\r
}\r
\r
void MainWindow::slotActionRotate(QAction* action)\r
{\r
qDebug() << "Rotate" << action->text();\r
- landscape = !landscape;\r
- settings->setValue("Landscape", landscape);\r
+\r
+ landscape = !tempLandscapeMode;\r
+ settings->setValue(LANDSCAPE, landscape);\r
setLandscapeMode(landscape);\r
}\r
\r
{\r
if(landscape)\r
{\r
+ tempLandscapeMode = true;\r
+ qDebug() << LANDSCAPE;\r
setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);\r
setAttribute(Qt::WA_Maemo5PortraitOrientation, false);\r
}\r
else\r
{\r
+ tempLandscapeMode = false;\r
+ qDebug() << PORTRAIT;\r
setAttribute(Qt::WA_Maemo5PortraitOrientation, true);\r
setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);\r
}\r
aboutText.append("Created with QtCreator.\n");\r
QMessageBox::about(this, "EasyList", aboutText);\r
}\r
+\r
+/**\r
+ * Is called when the Checked Bottom menu item is triggered.\r
+ * The menu item is a checkable item. So we need to check if it's checked or not.\r
+ *\r
+ * @fn slotActionCheckedBottom\r
+ * @param QAction* action - the action.\r
+ */\r
+void MainWindow::slotActionCheckedBottom(QAction* action)\r
+{\r
+ qDebug() << "Checked Bottom" << action->text() << listUi->actionChecked_Bottom->isChecked();\r
+ settings->setValue(CHECKED_ITEMS_TO_BOTTOM, listUi->actionChecked_Bottom->isChecked());\r
+}\r