Change back to real tabbed window, updates keysets
[pierogi] / forms / pirfavoritesform.cpp
1 #include "pirfavoritesform.h"
2 #include "ui_pirfavoritesform.h"
3
4 #include "mainwindow.h"
5 //#include "pirkeysetmanager.h"
6 #include "pirkeysetwidgetitem.h"
7
8 #include <QMaemo5InformationBox>
9
10 PIRFavoritesForm::PIRFavoritesForm(
11   MainWindow *mw)
12   : QWidget(0),
13     ui(new Ui::PIRFavoritesForm),
14     mainWindow(mw)
15 {
16   ui->setupUi(this);
17 }
18
19 PIRFavoritesForm::~PIRFavoritesForm()
20 {
21   delete ui;
22 }
23
24
25 void PIRFavoritesForm::selectPrevFavKeyset()
26 {
27   int size = ui->favoriteKeysetsWidget->count();
28
29   if (size == 0)
30   {
31     // No favorites, so nothing to do!
32     return;
33   }
34
35   int position = ui->favoriteKeysetsWidget->currentRow();
36
37   --position;
38   if (position < 0)
39   {
40     position = size - 1;
41   }
42
43   ui->favoriteKeysetsWidget->setCurrentRow(
44     position,
45     QItemSelectionModel::ClearAndSelect);
46
47   mainWindow->keysetSelectionChanged(
48     ui->favoriteKeysetsWidget->currentItem());
49
50   // Tell the user about the change:
51   QMaemo5InformationBox::information(
52     0,
53     ui->favoriteKeysetsWidget->item(position)->text());
54 }
55
56
57 void PIRFavoritesForm::selectNextFavKeyset()
58 {
59   int size = ui->favoriteKeysetsWidget->count();
60
61   if (size == 0)
62   {
63     // No favorites, so just return:
64     return;
65   }
66
67   int position = ui->favoriteKeysetsWidget->currentRow();
68
69   ++position;
70   if (position == size)
71   {
72     position = 0;
73   }
74
75   ui->favoriteKeysetsWidget->setCurrentRow(
76     position,
77     QItemSelectionModel::ClearAndSelect);
78
79   mainWindow->keysetSelectionChanged(
80     ui->favoriteKeysetsWidget->currentItem());
81
82   // Tell the user about the change:
83   QMaemo5InformationBox::information(
84     0,
85     ui->favoriteKeysetsWidget->item(position)->text());
86 }
87
88
89 void PIRFavoritesForm::addItem(
90   PIRKeysetWidgetItem *item)
91 {
92   ui->favoriteKeysetsWidget->addItem(item);
93 }
94
95
96 QListWidget *PIRFavoritesForm::getFavoritesListWidget()
97 {
98   return ui->favoriteKeysetsWidget;
99 }
100
101
102 void PIRFavoritesForm::on_addKeysetButton_clicked()
103 {
104   mainWindow->addCurrentKeyset(ui->favoriteKeysetsWidget);
105 }
106
107
108 void PIRFavoritesForm::on_removeKeysetButton_clicked()
109 {
110   mainWindow->removeFavoriteKeyset(ui->favoriteKeysetsWidget);
111 }