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 // Set a default value for CHECKED_ITEMS_TO_BOTTOM
\r
16 if(settings->contains(CHECKED_ITEMS_TO_BOTTOM) == false)
\r
18 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, false);
\r
20 ui->actionChecked_bottom->setChecked(settings->value(CHECKED_ITEMS_TO_BOTTOM).toBool());
\r
21 on_actionChecked_bottom_triggered();
\r
23 // Create a default for landscape mode.
\r
24 landscape = settings->value(LANDSCAPE).toBool();
\r
25 // If LANDSCAPE exists in QSettings.
\r
26 if(settings->contains(LANDSCAPE))
\r
28 // We use the LANDSCAPE value in the QSettings.
\r
29 landscape = settings->value(LANDSCAPE).toBool();
\r
33 // Otherwise we set our default into the QSettings.
\r
34 settings->setValue(LANDSCAPE, landscape);
\r
36 // If keyboard is opened at start. We do landscape mode.
\r
37 // Otherwise we do what's read from the QSettings.
\r
38 if(SystemSettings::getInstance()->getKeyboardClosed() == false)
\r
40 setLandscapeMode(true);
\r
44 setLandscapeMode(landscape);
\r
47 // Populate the QStackedWidget. ListForm is set as the current widget.
\r
48 listForm = new ListForm(this);
\r
49 editForm = new EditForm(this);
\r
51 connect(listForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
52 connect(listForm, SIGNAL(signalEditListPushButtonTriggered(SlideWidget*)), this, SLOT(changeWidget(SlideWidget*)));
\r
54 connect(editForm, SIGNAL(signalTransitionOutFinished()), this, SLOT(stateOutFinished()));
\r
55 connect(editForm, SIGNAL(signalCancelPushButtonClicked(SlideWidget*)), this, SLOT(changeWidget(SlideWidget*)));
\r
56 connect(editForm, SIGNAL(signalSavePushButtonClicked(SlideWidget*)), this, SLOT(changeWidget(SlideWidget*)));
\r
58 ui->stackedWidget->addWidget(listForm);
\r
59 ui->stackedWidget->addWidget(editForm);
\r
60 ui->stackedWidget->setCurrentWidget(listForm);
\r
63 MainForm::~MainForm()
\r
68 void MainForm::stateOutFinished()
\r
70 qDebug() << "Show new widget" << newIndex;
\r
71 ui->stackedWidget->setCurrentIndex(newIndex);
\r
72 SlideWidget * newWidget = dynamic_cast<SlideWidget * >(ui->stackedWidget->currentWidget());
\r
73 newWidget->move(0, -newWidget->height());
\r
74 newWidget->setStateIn();
\r
78 void MainForm::changeWidget(SlideWidget * currentWidget)
\r
80 currentWidget->initStates();
\r
81 int currentIndex = ui->stackedWidget->indexOf(currentWidget);
\r
82 // Because all widgets are started with StateOut as initial state, we
\r
83 // need to reset the current widget to StateIn. The view is showing the
\r
84 // current widget at the place of its StateIn position. But the state
\r
85 // is never set to StateIn.
\r
86 currentWidget->setStateIn();
\r
87 qDebug() << "Current widget index" << currentIndex;
\r
88 if(currentIndex < ui->stackedWidget->count()-1)
\r
90 newIndex = currentIndex+1;
\r
91 currentWidget->setStateOut();
\r
95 if(ui->stackedWidget->count() > 0)
\r
98 currentWidget->setStateOut();
\r
102 qDebug() << "StackedWidget does not have any widgets";
\r
105 qDebug() << "New widget index" << newIndex;
\r
108 void MainForm::keyboardClosed(bool closed)
\r
110 // When keyboard is opened.
\r
111 if(closed == false)
\r
113 setLandscapeMode(true);
\r
117 setLandscapeMode(landscape);
\r
121 void MainForm::setLandscapeMode(bool landscape)
\r
125 tempLandscapeMode = true;
\r
126 qDebug() << LANDSCAPE;
\r
127 #ifdef Q_WS_MAEMO_5
\r
128 setAttribute(Qt::WA_Maemo5LandscapeOrientation, true);
\r
129 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
134 tempLandscapeMode = false;
\r
135 qDebug() << PORTRAIT;
\r
136 #ifdef Q_WS_MAEMO_5
\r
137 setAttribute(Qt::WA_Maemo5PortraitOrientation, true);
\r
138 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
143 void MainForm::on_actionRotate_triggered()
\r
145 qDebug() << "Rotate";
\r
147 landscape = !tempLandscapeMode;
\r
148 settings->setValue(LANDSCAPE, landscape);
\r
149 setLandscapeMode(landscape);
\r
152 void MainForm::on_actionAbout_triggered()
\r
154 qDebug() << "About";
\r
156 aboutText.append("EasyList (c) 2010\n\n");
\r
157 aboutText.append("Created by Willem Liu.\n");
\r
158 aboutText.append("Created with QtCreator.\n");
\r
159 QMessageBox::about(this, "EasyList", aboutText);
\r
162 void MainForm::on_actionChecked_bottom_triggered()
\r
164 bool sortToBottom = ui->actionChecked_bottom->isChecked();
\r
165 qDebug() << "Checked Bottom" << sortToBottom;
\r
166 settings->setValue(CHECKED_ITEMS_TO_BOTTOM, sortToBottom);
\r
167 MyCheckBoxContainer::getInstance()->setSortCheckedToBottom(sortToBottom);
\r
170 void MainForm::closeEvent(QCloseEvent *event)
\r
172 settings->setValue(LIST_TEXT, MyCheckBoxContainer::getInstance()->getListText());
\r
176 void MainForm::on_actionAuto_Orientation_triggered()
\r
178 if(ui->actionAuto_Orientation->isChecked())
\r
180 #ifdef Q_WS_MAEMO_5
\r
181 setAttribute(Qt::WA_Maemo5PortraitOrientation, false);
\r
182 setAttribute(Qt::WA_Maemo5LandscapeOrientation, false);
\r
183 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
\r
188 #ifdef Q_WS_MAEMO_5
\r
189 setAttribute(Qt::WA_Maemo5AutoOrientation, false);
\r
191 setLandscapeMode(landscape);
\r