1 | #include "MainWindow.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 |
|
---|
5 | #include "dic.hxx"
|
---|
6 |
|
---|
7 | #include "DockWindow.h"
|
---|
8 | #include "HtmlDelegate.h"
|
---|
9 | #include "CheckBoxDelegate.h"
|
---|
10 |
|
---|
11 | using namespace std;
|
---|
12 |
|
---|
13 | MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
|
---|
14 | {
|
---|
15 | // setupUi MUST be called before the DimNetwork is initilized
|
---|
16 | // In this way it can be ensured that nothing from the
|
---|
17 | // DimNetwork arrives before all graphical elements are
|
---|
18 | // initialized. This is a simple but very powerfull trick.
|
---|
19 | setupUi(this);
|
---|
20 |
|
---|
21 | // Now here we can do further setup which should be done
|
---|
22 | // before the gui is finally displayed.
|
---|
23 | fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
|
---|
24 | fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
|
---|
25 | fDimCmdDescription->setItemDelegate(new HtmlDelegate);
|
---|
26 |
|
---|
27 | fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
|
---|
28 | fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
|
---|
29 | fDimSvcDescription->setItemDelegate(new HtmlDelegate);
|
---|
30 |
|
---|
31 | fStatusBar->showMessage(PACKAGE_STRING" | "PACKAGE_URL" | report bugs to <"PACKAGE_BUGREPORT">");
|
---|
32 |
|
---|
33 | fFtuLED[0] = fFtuLEDPrototype;
|
---|
34 |
|
---|
35 | for (int i=1; i<40; i++)
|
---|
36 | {
|
---|
37 | QPushButton *b = new QPushButton(static_cast<QWidget*>(fFtuLEDPrototype->parent()));
|
---|
38 |
|
---|
39 | b->setEnabled(fFtuLEDPrototype->isEnabled());
|
---|
40 | b->setSizePolicy(fFtuLEDPrototype->sizePolicy());
|
---|
41 | b->setMaximumSize(fFtuLEDPrototype->maximumSize());
|
---|
42 | b->setIcon(fFtuLEDPrototype->icon());
|
---|
43 | b->setIconSize(fFtuLEDPrototype->iconSize());
|
---|
44 | b->setCheckable(fFtuLEDPrototype->isCheckable());
|
---|
45 | b->setFlat(fFtuLEDPrototype->isFlat());
|
---|
46 |
|
---|
47 | fFtuLedLayout->addWidget(b, i/10+1, i%10+1, 1, 1);
|
---|
48 |
|
---|
49 | fFtuLED[i] = b;
|
---|
50 | }
|
---|
51 |
|
---|
52 | for (int i=0; i<40; i++)
|
---|
53 | {
|
---|
54 | fFtuLED[i]->setObjectName(QString::fromUtf8("fFtuLED")+QString::number(i));
|
---|
55 | QObject::connect(fFtuLED[i], SIGNAL(clicked()), this, SLOT(slot_fFtuLED_clicked()));
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | void MainWindow::SelectTab(const QString &name)
|
---|
60 | {
|
---|
61 | for (int i=0; i<fTabWidget->count(); i++)
|
---|
62 | if (fTabWidget->tabText(i)==name)
|
---|
63 | {
|
---|
64 | fTabWidget->setCurrentIndex(i);
|
---|
65 | break;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | void MainWindow::on_fShutdown_clicked()
|
---|
70 | {
|
---|
71 | DimClient::sendCommand("DIS_DNS/KILL_SERVERS", NULL, 0);
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | void MainWindow::on_fShutdownAll_clicked()
|
---|
76 | {
|
---|
77 | DimClient::sendCommand("DIS_DNS/KILL_SERVERS", NULL, 0);
|
---|
78 | DimClient::sendCommand("DIS_DNS/EXIT", 1);
|
---|
79 | }
|
---|
80 |
|
---|
81 | void MainWindow::on_fTabWidget_tabCloseRequested(int which)
|
---|
82 | {
|
---|
83 | // To get the correct size we have to switch to this tab
|
---|
84 | // An alternative would be to take the size of the current tab
|
---|
85 | fTabWidget->setCurrentIndex(which);
|
---|
86 |
|
---|
87 | QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
|
---|
88 | if (!w)
|
---|
89 | {
|
---|
90 | cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
|
---|
91 | return;
|
---|
92 | }
|
---|
93 |
|
---|
94 | QDockWidget *d = w->findChild<QDockWidget*>();
|
---|
95 | if (!d)
|
---|
96 | {
|
---|
97 | cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
|
---|
98 | return;
|
---|
99 | }
|
---|
100 |
|
---|
101 | new DockWindow(d, fTabWidget->tabText(which));
|
---|
102 | fTabWidget->removeTab(which);
|
---|
103 |
|
---|
104 | if (fTabWidget->count()==1)
|
---|
105 | fTabWidget->setTabsClosable(false);
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 | void MainWindow::on_fChatSend_clicked()
|
---|
110 | {
|
---|
111 | if (DimClient::sendCommand("CHAT/MSG", fChatMessage->displayText().toStdString().c_str()))
|
---|
112 | fChatMessage->clear();
|
---|
113 | }
|
---|
114 |
|
---|
115 | void MainWindow::on_fStatusLoggerLed_clicked()
|
---|
116 | {
|
---|
117 | SelectTab("Logger");
|
---|
118 | }
|
---|
119 |
|
---|
120 | void MainWindow::on_fStatusChatLed_clicked()
|
---|
121 | {
|
---|
122 | SelectTab("Chat");
|
---|
123 | }
|
---|
124 |
|
---|
125 | void MainWindow::on_fStatusFTMLed_clicked()
|
---|
126 | {
|
---|
127 | SelectTab("Trigger");
|
---|
128 | }
|
---|
129 |
|
---|
130 | void MainWindow::slot_fFtuLED_clicked()
|
---|
131 | {
|
---|
132 | for (int i=0; i<40; i++)
|
---|
133 | if (sender()==fFtuLED[i])
|
---|
134 | cout << "--------------> clicked #" << i << endl;
|
---|
135 | }
|
---|