panelspane.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966
  1. #include "panelspane.h"
  2. #include "../dialogs/addappletdialog.h"
  3. #include "../dialogs/appmenudialog.h"
  4. #include "../dialogs/volumedialog.h"
  5. #include "../dialogs/kbindicatordialog.h"
  6. #include "../dialogs/datetimedialog.h"
  7. #include "../dialogs/usermenudialog.h"
  8. #include "../dialogs/windowlistdialog.h"
  9. #include "../dialogs/localipv4dialog.h"
  10. #include "../dialogs/workspacesdialog.h"
  11. #include "../dialogs/launcherdialog.h"
  12. #include "../dialogs/clioutputdialog.h"
  13. void PanelsPane::setPaneContents() {
  14. mContentsWidget = new QWidget();
  15. QVBoxLayout* contentsLayout = new QVBoxLayout(mContentsWidget);
  16. mContentsWidget->setObjectName("innerPane");
  17. // Adding widgets
  18. QWidget* widget = new QWidget();
  19. QHBoxLayout* layout = new QHBoxLayout(widget);
  20. layout->setContentsMargins(0, 0, 0, 0);
  21. QVBoxLayout* panelsListLayout = new QVBoxLayout();
  22. QListWidget* panelsListWidget = new QListWidget();
  23. for (int i = 1; i <= getConfigValue("countPanels").toInt(); ++i) {
  24. QString cfgName = QString("panel%1").arg(QString::number(i));
  25. if (!getConfigValue(cfgName).isNull()) {
  26. QString name = QString(" Panel %1").arg(QString::number(i));
  27. QListWidgetItem* panelItem = new QListWidgetItem(name);
  28. panelItem->setIcon(QIcon::fromTheme("cs-applets"));
  29. panelsListWidget->addItem(panelItem);
  30. }
  31. }
  32. QString listWidgetStyle = QString("QListView::item:selected { "
  33. "background-color: %1; color: #ffffff; "
  34. "};").arg(getConfigValue("accent").toString());
  35. panelsListWidget->setStyleSheet(listWidgetStyle);
  36. panelsListWidget->setFont(mFont);
  37. panelsListLayout->addWidget(panelsListWidget);
  38. QVBoxLayout* listButtonsLayout = new QVBoxLayout();
  39. QPushButton* newPanelButton = new QPushButton(tr("+"));
  40. newPanelButton->setFont(mFont);
  41. listButtonsLayout->addWidget(newPanelButton);
  42. QPushButton* removePanelButton = new QPushButton(tr("-"));
  43. removePanelButton->setFont(mFont);
  44. listButtonsLayout->addWidget(removePanelButton);
  45. panelsListLayout->addLayout(listButtonsLayout);
  46. layout->addLayout(panelsListLayout);
  47. QWidget* currentPanelWidget = new QWidget();
  48. QVBoxLayout* panelLayout = new QVBoxLayout(currentPanelWidget);
  49. //panelLayout->setSpacing(10);
  50. QLabel* appletsLabel = new QLabel(tr("Applets"));
  51. appletsLabel->setFont(mTitleFont);
  52. panelLayout->addWidget(appletsLabel);
  53. QHBoxLayout* appletsLayout = new QHBoxLayout();
  54. appletsLayout->setContentsMargins(10, 1, 1, 1);
  55. QListWidget* appletsListWidget = new QListWidget();
  56. appletsListWidget->setStyleSheet(listWidgetStyle);
  57. appletsListWidget->setFont(mFont);
  58. appletsLayout->addWidget(appletsListWidget);
  59. QVBoxLayout* buttonsLayout = new QVBoxLayout();
  60. QPushButton* addAppletButton = new QPushButton("+");
  61. addAppletButton->setMaximumWidth(40);
  62. buttonsLayout->addWidget(addAppletButton);
  63. QPushButton* removeAppletButton = new QPushButton("-");
  64. removeAppletButton->setMaximumWidth(40);
  65. buttonsLayout->addWidget(removeAppletButton);
  66. QPushButton* moveUpButton = new QPushButton("⬆️"); // U+2B06 - Up arrow
  67. moveUpButton->setMaximumWidth(40);
  68. buttonsLayout->addWidget(moveUpButton);
  69. QPushButton* moveDownButton = new QPushButton("⬇"); // U+2B07 - Down arrow
  70. moveDownButton->setMaximumWidth(40);
  71. buttonsLayout->addWidget(moveDownButton);
  72. QPushButton* configureButton = new QPushButton();
  73. configureButton->setIcon(QIcon::fromTheme("preferences-system"));
  74. configureButton->setMaximumWidth(40);
  75. buttonsLayout->addWidget(configureButton);
  76. appletsLayout->addLayout(buttonsLayout);
  77. panelLayout->addLayout(appletsLayout);
  78. QLabel* autoHideLabel = new QLabel(tr("Auto Hide"));
  79. autoHideLabel->setFont(mTitleFont);
  80. panelLayout->addWidget(autoHideLabel);
  81. QVBoxLayout* autoHideLayout = new QVBoxLayout();
  82. autoHideLayout->setContentsMargins(10, 1, 1, 1);
  83. QCheckBox* enableAutoHideCheckBox = new QCheckBox(tr("Enable Auto Hide"));
  84. enableAutoHideCheckBox->setFont(mFont);
  85. autoHideLayout->addWidget(enableAutoHideCheckBox);
  86. QHBoxLayout* autoHideIntervalLayout = new QHBoxLayout();
  87. QLabel* autoHideIntervalLabel = new QLabel(tr("Auto Hide Interval"));
  88. autoHideIntervalLabel->setFont(mTitleFont);
  89. autoHideIntervalLayout->addWidget(autoHideIntervalLabel);
  90. QSpinBox* autoHideIntervalSpinBox = new QSpinBox();
  91. autoHideIntervalSpinBox->setFont(mFont);
  92. autoHideIntervalSpinBox->setMinimum(100);
  93. autoHideIntervalSpinBox->setMaximum(32000);
  94. autoHideIntervalLayout->addWidget(autoHideIntervalSpinBox);
  95. autoHideLayout->addLayout(autoHideIntervalLayout);
  96. panelLayout->addLayout(autoHideLayout);
  97. QLabel* geometryLabel = new QLabel(tr("Geometry"));
  98. geometryLabel->setFont(mTitleFont);
  99. panelLayout->addWidget(geometryLabel);
  100. QVBoxLayout* geometryLayout = new QVBoxLayout();
  101. geometryLayout->setContentsMargins(10, 1, 1, 1);
  102. QHBoxLayout* thicknessLayout = new QHBoxLayout();
  103. QLabel* thicknessLabel = new QLabel(tr("Thickness"));
  104. thicknessLabel->setFont(mTitleFont);
  105. thicknessLayout->addWidget(thicknessLabel);
  106. QSpinBox* thicknessSpinBox = new QSpinBox();
  107. thicknessSpinBox->setFont(mFont);
  108. thicknessSpinBox->setMinimum(0);
  109. thicknessSpinBox->setMaximum(256);
  110. thicknessLayout->addWidget(thicknessSpinBox);
  111. geometryLayout->addLayout(thicknessLayout);
  112. QHBoxLayout* screenLayout = new QHBoxLayout();
  113. QLabel* screenLabel = new QLabel(tr("Screen"));
  114. screenLabel->setFont(mTitleFont);
  115. screenLayout->addWidget(screenLabel);
  116. QComboBox* screenComboBox = new QComboBox();
  117. screenComboBox->setFont(mFont);
  118. screenComboBox->addItem(tr("(primary screen)"));
  119. foreach (QScreen* screen, qApp->screens()) {
  120. screenComboBox->addItem(screen->name());
  121. }
  122. QString comboBoxStyle = QString("QComboBox::item:selected { "
  123. "background-color: %1; color: #ffffff; "
  124. "};").arg(getConfigValue("accent").toString());
  125. screenComboBox->setStyleSheet(comboBoxStyle);
  126. screenLayout->addWidget(screenComboBox);
  127. geometryLayout->addLayout(screenLayout);
  128. QCheckBox* stretchCheckBox = new QCheckBox(tr("Stretch to the screen size"));
  129. stretchCheckBox->setFont(mFont);
  130. geometryLayout->addWidget(stretchCheckBox);
  131. QCheckBox* setOnCenterCheckBox = new QCheckBox(tr("Set on the center"));
  132. setOnCenterCheckBox->setFont(mFont);
  133. geometryLayout->addWidget(setOnCenterCheckBox);
  134. QHBoxLayout* axisShiftLayout = new QHBoxLayout();
  135. QLabel* shiftLabel = new QLabel(tr("Axis shift"));
  136. shiftLabel->setFont(mTitleFont);
  137. axisShiftLayout->addWidget(shiftLabel);
  138. QSpinBox* shiftSpinBox = new QSpinBox();
  139. shiftSpinBox->setFont(mFont);
  140. shiftSpinBox->setMinimum(0);
  141. shiftSpinBox->setMaximum(INT_MAX);
  142. axisShiftLayout->addWidget(shiftSpinBox);
  143. geometryLayout->addLayout(axisShiftLayout);
  144. QHBoxLayout* locationLayout = new QHBoxLayout();
  145. QLabel* locationLabel = new QLabel(tr("Location"));
  146. locationLabel->setFont(mTitleFont);
  147. locationLayout->addWidget(locationLabel);
  148. QRadioButton* topRadioButton = new QRadioButton(tr("Top"));
  149. topRadioButton->setFont(mFont);
  150. locationLayout->addWidget(topRadioButton);
  151. QRadioButton* bottomRadioButton = new QRadioButton(tr("Bottom"));
  152. bottomRadioButton->setFont(mFont);
  153. locationLayout->addWidget(bottomRadioButton);
  154. QRadioButton* leftRadioButton = new QRadioButton(tr("Left"));
  155. leftRadioButton->setFont(mFont);
  156. locationLayout->addWidget(leftRadioButton);
  157. QRadioButton* rightRadioButton = new QRadioButton(tr("Right"));
  158. rightRadioButton->setFont(mFont);
  159. locationLayout->addWidget(rightRadioButton);
  160. geometryLayout->addLayout(locationLayout);
  161. QHBoxLayout* launcherIconSizeLayout = new QHBoxLayout();
  162. QLabel* launcherIconSizeLabel = new QLabel(tr("Launcher Icon Size"));
  163. launcherIconSizeLabel->setFont(mTitleFont);
  164. launcherIconSizeLayout->addWidget(launcherIconSizeLabel);
  165. QSpinBox* launcherIconSizeSpinBox = new QSpinBox();
  166. launcherIconSizeSpinBox->setMinimum(0);
  167. launcherIconSizeSpinBox->setMaximum(256);
  168. launcherIconSizeSpinBox->setFont(mFont);
  169. launcherIconSizeLayout->addWidget(launcherIconSizeSpinBox);
  170. geometryLayout->addLayout(launcherIconSizeLayout);
  171. panelLayout->addLayout(geometryLayout);
  172. QLabel* bgrImageLabel = new QLabel(tr("Background Image"));
  173. bgrImageLabel->setFont(mTitleFont);
  174. panelLayout->addWidget(bgrImageLabel);
  175. QHBoxLayout* bgrImageLayout = new QHBoxLayout();
  176. bgrImageLayout->setContentsMargins(10, 1, 1, 1);
  177. QLineEdit* bgrImagePathLineEdit = new QLineEdit();
  178. bgrImagePathLineEdit->setFont(mFont);
  179. bgrImagePathLineEdit->setPlaceholderText(tr("Type path here..."));
  180. bgrImagePathLineEdit->setClearButtonEnabled(true);
  181. bgrImageLayout->addWidget(bgrImagePathLineEdit);
  182. QPushButton* chooseButton = new QPushButton("...");
  183. bgrImageLayout->addWidget(chooseButton);
  184. panelLayout->addLayout(bgrImageLayout);
  185. QLabel* layoutSettingsLabel = new QLabel(tr("Layout Settings"));
  186. layoutSettingsLabel->setFont(mTitleFont);
  187. panelLayout->addWidget(layoutSettingsLabel);
  188. QVBoxLayout* layoutSettingsLayout = new QVBoxLayout();
  189. layoutSettingsLayout->setContentsMargins(10, 1, 1, 1);
  190. QHBoxLayout* spacingLayout = new QHBoxLayout();
  191. QLabel* spacingLabel = new QLabel(tr("Spacing between applets"));
  192. spacingLabel->setFont(mTitleFont);
  193. spacingLayout->addWidget(spacingLabel);
  194. QSpinBox* spacingSpinBox = new QSpinBox();
  195. spacingSpinBox->setFont(mFont);
  196. spacingSpinBox->setMinimum(0);
  197. spacingSpinBox->setMaximum(256);
  198. spacingLayout->addWidget(spacingSpinBox);
  199. layoutSettingsLayout->addLayout(spacingLayout);
  200. QHBoxLayout* marginLayout = new QHBoxLayout();
  201. QLabel* marginLabel = new QLabel(tr("Margin"));
  202. marginLabel->setFont(mTitleFont);
  203. marginLayout->addWidget(marginLabel);
  204. QSpinBox* marginSpinBox = new QSpinBox();
  205. marginSpinBox->setFont(mFont);
  206. marginSpinBox->setMinimum(0);
  207. marginSpinBox->setMaximum(500);
  208. marginLayout->addWidget(marginSpinBox);
  209. layoutSettingsLayout->addLayout(marginLayout);
  210. panelLayout->addLayout(layoutSettingsLayout);
  211. QHBoxLayout* opacityLayout = new QHBoxLayout();
  212. QLabel* opacityLabel = new QLabel(tr("Opacity"));
  213. opacityLabel->setFont(mTitleFont);
  214. opacityLayout->addWidget(opacityLabel);
  215. QDoubleSpinBox* opacitySpinBox = new QDoubleSpinBox();
  216. opacitySpinBox->setFont(mFont);
  217. opacitySpinBox->setMinimum(0);
  218. opacitySpinBox->setMaximum(1);
  219. opacityLayout->addWidget(opacitySpinBox);
  220. panelLayout->addLayout(opacityLayout);
  221. mSaveButton = new QPushButton(tr("Save settings"));
  222. mSaveButton->setFont(mFont);
  223. panelLayout->addWidget(mSaveButton);
  224. mSaveButton->setVisible(false);
  225. layout->addWidget(currentPanelWidget);
  226. contentsLayout->addWidget(widget);
  227. //contentsLayout->setContentsMargins(0, 0, 0, 0);
  228. // Make connections
  229. connect(panelsListWidget, &QListWidget::itemSelectionChanged,
  230. this, [this, panelsListWidget, appletsListWidget, enableAutoHideCheckBox,
  231. autoHideIntervalSpinBox, thicknessSpinBox,
  232. screenComboBox, stretchCheckBox, setOnCenterCheckBox, shiftSpinBox,
  233. topRadioButton, bottomRadioButton, leftRadioButton, rightRadioButton,
  234. launcherIconSizeSpinBox, bgrImagePathLineEdit,
  235. spacingSpinBox, marginSpinBox, opacitySpinBox]() {
  236. int id = panelsListWidget->currentItem()->text().split(' ').last().toInt();
  237. setPanelSettings(id, appletsListWidget, enableAutoHideCheckBox, autoHideIntervalSpinBox,
  238. thicknessSpinBox, screenComboBox, stretchCheckBox, setOnCenterCheckBox,
  239. shiftSpinBox, topRadioButton, bottomRadioButton, leftRadioButton,
  240. rightRadioButton, launcherIconSizeSpinBox, bgrImagePathLineEdit,
  241. spacingSpinBox, marginSpinBox, opacitySpinBox);
  242. QDBusConnection bus = QDBusConnection::sessionBus();
  243. QDBusMessage req = QDBusMessage::createMethodCall("org.plainDE.plainPanel",
  244. "/Actions",
  245. "org.plainDE.actions",
  246. "highlightPanel");
  247. QList<QVariant> args = { id };
  248. req.setArguments(args);
  249. QDBusMessage resp = bus.call(req);
  250. });
  251. connect(moveUpButton, &QPushButton::clicked, this, [appletsListWidget, this]() {
  252. if (!appletsListWidget->selectedItems().isEmpty()) {
  253. QListWidgetItem* item = appletsListWidget->selectedItems()[0];
  254. int currentRow = appletsListWidget->currentRow();
  255. if (currentRow > 0) {
  256. appletsListWidget->takeItem(currentRow);
  257. appletsListWidget->insertItem(currentRow - 1, item);
  258. }
  259. appletsListWidget->setCurrentRow(currentRow - 1);
  260. mSaveButton->setVisible(true);
  261. }
  262. });
  263. connect(moveDownButton, &QPushButton::clicked, this, [appletsListWidget, this]() {
  264. if (!appletsListWidget->selectedItems().isEmpty()) {
  265. QListWidgetItem* item = appletsListWidget->selectedItems()[0];
  266. int currentRow = appletsListWidget->currentRow();
  267. if (currentRow < appletsListWidget->count() - 1) {
  268. appletsListWidget->takeItem(currentRow);
  269. appletsListWidget->insertItem(currentRow + 1, item);
  270. }
  271. appletsListWidget->setCurrentRow(currentRow + 1);
  272. mSaveButton->setVisible(true);
  273. }
  274. });
  275. connect(removeAppletButton, &QPushButton::clicked, this, [appletsListWidget, this]() {
  276. if (!appletsListWidget->selectedItems().isEmpty()) {
  277. QListWidgetItem* item = appletsListWidget->currentItem();
  278. if (item->text().startsWith("clioutput:")) {
  279. QString appletName = item->text().split(':').last();
  280. QString path = QDir::homePath() + "/.config/plainDE/clioutput-applets/" + appletName + ".json";
  281. QMessageBox msgBox(this);
  282. msgBox.setWindowTitle("Deleting CLI Output Applet");
  283. QString warning = QString("Do you also want to delete matching config file? (%1)\n"
  284. "This action cannot be undone.").arg(path);
  285. msgBox.setText(warning);
  286. msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  287. msgBox.setIcon(QMessageBox::Question);
  288. if (msgBox.exec() == QMessageBox::Yes) {
  289. QFile file(path);
  290. file.remove();
  291. }
  292. }
  293. delete item;
  294. mSaveButton->setVisible(true);
  295. }
  296. });
  297. connect(addAppletButton, &QPushButton::clicked, this, [this, appletsListWidget,
  298. panelsListWidget]() {
  299. int panelID = panelsListWidget->currentItem()->text().split(' ').last().toInt();
  300. AddAppletDialog* dialog = new AddAppletDialog(mCfgObj, panelID, appletsListWidget);
  301. dialog->setPaneContents();
  302. dialog->show();
  303. });
  304. QAbstractItemModel* model = appletsListWidget->model();
  305. connect(model, &QAbstractItemModel::rowsInserted, this, [this]() {
  306. mSaveButton->setVisible(true);
  307. });
  308. connect(enableAutoHideCheckBox, &QCheckBox::stateChanged, this, [this, enableAutoHideCheckBox,
  309. autoHideIntervalSpinBox]() {
  310. mSaveButton->setVisible(true);
  311. autoHideIntervalSpinBox->setEnabled(enableAutoHideCheckBox->isChecked());
  312. });
  313. connect(autoHideIntervalSpinBox, static_cast<void(QSpinBox::*)(int)>(
  314. &QSpinBox::valueChanged), this, [this]() {
  315. mSaveButton->setVisible(true);
  316. });
  317. connect(thicknessSpinBox, static_cast<void(QSpinBox::*)(int)>(
  318. &QSpinBox::valueChanged), this, [this]() {
  319. mSaveButton->setVisible(true);
  320. });
  321. connect(screenComboBox, static_cast<void(QComboBox::*)(int)>(
  322. &QComboBox::currentIndexChanged), this, [this]() {
  323. mSaveButton->setVisible(true);
  324. });
  325. connect(stretchCheckBox, &QCheckBox::stateChanged, this, [this, stretchCheckBox,
  326. setOnCenterCheckBox]() {
  327. mSaveButton->setVisible(true);
  328. if (stretchCheckBox->isChecked()) {
  329. setOnCenterCheckBox->setEnabled(false);
  330. setOnCenterCheckBox->setChecked(false);
  331. }
  332. else {
  333. setOnCenterCheckBox->setEnabled(true);
  334. }
  335. });
  336. connect(setOnCenterCheckBox, &QCheckBox::stateChanged, this, [this]() {
  337. mSaveButton->setVisible(true);
  338. });
  339. connect(shiftSpinBox, static_cast<void(QSpinBox::*)(int)>(
  340. &QSpinBox::valueChanged), this, [this]() {
  341. mSaveButton->setVisible(true);
  342. });
  343. connect(topRadioButton, &QRadioButton::clicked, this, [this]() {
  344. mSaveButton->setVisible(true);
  345. });
  346. connect(bottomRadioButton, &QRadioButton::clicked, this, [this]() {
  347. mSaveButton->setVisible(true);
  348. });
  349. connect(leftRadioButton, &QRadioButton::clicked, this, [this]() {
  350. mSaveButton->setVisible(true);
  351. });
  352. connect(rightRadioButton, &QRadioButton::clicked, this, [this]() {
  353. mSaveButton->setVisible(true);
  354. });
  355. connect(launcherIconSizeSpinBox, static_cast<void(QSpinBox::*)(int)>(
  356. &QSpinBox::valueChanged), this, [this]() {
  357. mSaveButton->setVisible(true);
  358. });
  359. connect(bgrImagePathLineEdit, &QLineEdit::textChanged, this, [this]() {
  360. mSaveButton->setVisible(true);
  361. });
  362. connect(chooseButton, &QPushButton::clicked, this, [this, bgrImagePathLineEdit]() {
  363. QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
  364. QDir::homePath(),
  365. "Images (*.png *.jpg *.jpeg)");
  366. if (!fileName.isEmpty()) {
  367. bgrImagePathLineEdit->setText(fileName);
  368. }
  369. });
  370. connect(spacingSpinBox, static_cast<void(QSpinBox::*)(int)>(
  371. &QSpinBox::valueChanged), this, [this]() {
  372. mSaveButton->setVisible(true);
  373. });
  374. connect(marginSpinBox, static_cast<void(QSpinBox::*)(int)>(
  375. &QSpinBox::valueChanged), this, [this]() {
  376. mSaveButton->setVisible(true);
  377. });
  378. connect(opacitySpinBox, static_cast<void(QDoubleSpinBox::*)(double)>(
  379. &QDoubleSpinBox::valueChanged), this, [this]() {
  380. mSaveButton->setVisible(true);
  381. });
  382. connect(mSaveButton, &QPushButton::clicked, this, [this, panelsListWidget, appletsListWidget, enableAutoHideCheckBox,
  383. autoHideIntervalSpinBox, thicknessSpinBox, screenComboBox, stretchCheckBox,
  384. setOnCenterCheckBox, shiftSpinBox, topRadioButton, bottomRadioButton,
  385. leftRadioButton, rightRadioButton, launcherIconSizeSpinBox, bgrImagePathLineEdit,
  386. spacingSpinBox, marginSpinBox, opacitySpinBox]() {
  387. int id = panelsListWidget->currentItem()->text().split(' ').last().toInt();
  388. prepareToSave(id, appletsListWidget, enableAutoHideCheckBox, autoHideIntervalSpinBox,
  389. thicknessSpinBox, screenComboBox, stretchCheckBox, setOnCenterCheckBox,
  390. shiftSpinBox, topRadioButton, bottomRadioButton, leftRadioButton,
  391. rightRadioButton, launcherIconSizeSpinBox, bgrImagePathLineEdit,
  392. spacingSpinBox, marginSpinBox, opacitySpinBox);
  393. saveConfig();
  394. mSaveButton->setVisible(false);
  395. });
  396. connect(configureButton, &QPushButton::clicked, this, [this, appletsListWidget, panelsListWidget]() {
  397. if (!appletsListWidget->selectedItems().isEmpty()) {
  398. QListWidgetItem* item = appletsListWidget->currentItem();
  399. QString text = item->text();
  400. if (!text.compare("App Menu")) {
  401. AppMenuDialog* dialog = new AppMenuDialog(mCfgObj);
  402. dialog->setPaneContents();
  403. dialog->show();
  404. }
  405. else if (!text.compare("Volume")) {
  406. VolumeDialog* dialog = new VolumeDialog(mCfgObj);
  407. dialog->setPaneContents();
  408. dialog->show();
  409. }
  410. else if (!text.compare("Keyboard Layout")) {
  411. KbIndicatorDialog* dialog = new KbIndicatorDialog(mCfgObj);
  412. dialog->setPaneContents();
  413. dialog->show();
  414. }
  415. else if (!text.compare("Date & Time")) {
  416. DateTimeDialog* dialog = new DateTimeDialog(mCfgObj);
  417. dialog->setPaneContents();
  418. dialog->show();
  419. }
  420. else if (!text.compare("User Menu")) {
  421. UserMenuDialog* dialog = new UserMenuDialog(mCfgObj);
  422. dialog->setPaneContents();
  423. dialog->show();
  424. }
  425. else if (!text.compare("Window List")) {
  426. WindowListDialog* dialog = new WindowListDialog(mCfgObj);
  427. dialog->setPaneContents();
  428. dialog->show();
  429. }
  430. else if (!text.compare("Local IPv4 Address")) {
  431. LocalIPv4Dialog* dialog = new LocalIPv4Dialog(mCfgObj);
  432. dialog->setPaneContents();
  433. dialog->show();
  434. }
  435. else if (!text.compare("Workspaces")) {
  436. WorkspacesDialog* dialog = new WorkspacesDialog(mCfgObj);
  437. dialog->setPaneContents();
  438. dialog->show();
  439. }
  440. else if (text.startsWith("launcher")) {
  441. int panelID = panelsListWidget->currentItem()->text().split(' ').last().toInt();
  442. LauncherDialog* dialog = new LauncherDialog(mCfgObj,
  443. panelID,
  444. false,
  445. appletsListWidget->currentRow(),
  446. appletsListWidget);
  447. dialog->setPaneContents();
  448. dialog->show();
  449. }
  450. else if (text.startsWith("clioutput")) {
  451. int panelID = panelsListWidget->currentItem()->text().split(' ').last().toInt();
  452. CLIOutputDialog* dialog = new CLIOutputDialog(mCfgObj,
  453. panelID,
  454. false,
  455. appletsListWidget->currentRow(),
  456. appletsListWidget);
  457. dialog->setPaneContents();
  458. dialog->show();
  459. }
  460. else {
  461. QMessageBox msg(this);
  462. msg.setWindowTitle("Information");
  463. msg.setText(tr("There are no aditional options for this applet."));
  464. msg.setStandardButtons(QMessageBox::Ok);
  465. msg.setIcon(QMessageBox::Information);
  466. msg.exec();
  467. }
  468. }
  469. });
  470. connect(newPanelButton, &QPushButton::clicked, this, [this, panelsListWidget]() {
  471. int lastNumber = 0;
  472. int final = panelsListWidget->count() + 1;
  473. bool orderOk = true;
  474. for (int i = 0; i < panelsListWidget->count(); ++i) {
  475. int panelID = panelsListWidget->item(i)->text().split(' ').last().toInt();
  476. if (panelID - lastNumber == 1) {
  477. lastNumber += 1;
  478. }
  479. else {
  480. final = i;
  481. orderOk = false;
  482. break;
  483. }
  484. }
  485. int newPanelID = (!orderOk) ? final + 1 : lastNumber + 1;
  486. QJsonObject newPanelObj;
  487. newPanelObj["applets"] = QJsonValue(QJsonArray());
  488. newPanelObj["thickness"] = QJsonValue(28);
  489. newPanelObj["screen"] = QJsonValue("");
  490. newPanelObj["expand"] = QJsonValue(true);
  491. newPanelObj["shift"] = QJsonValue(0);
  492. QHash<QString, bool> locations;
  493. locations["top"] = true;
  494. locations["bottom"] = true;
  495. locations["left"] = true;
  496. locations["right"] = true;
  497. for (int i = 1; i <= panelsListWidget->count(); ++i) {
  498. QString panelName = QString("panel%1").arg(QString::number(i));
  499. QString location = getConfigValue(panelName, "location").toString();
  500. locations[location] = false;
  501. }
  502. QString freeLocation = locations.key(true, "top");
  503. newPanelObj["location"] = QJsonValue(freeLocation);
  504. newPanelObj["launcherIconSize"] = QJsonValue(22);
  505. newPanelObj["spacing"] = QJsonValue(5);
  506. newPanelObj["margin"] = QJsonValue(5);
  507. newPanelObj["opacity"] = QJsonValue(0.85);
  508. QString newPanelName = QString("panel%1").arg(QString::number(newPanelID));
  509. setEntry(newPanelName, newPanelObj);
  510. panelsListWidget->clear();
  511. for (int i = 1; i <= getConfigValue("countPanels").toInt(); ++i) {
  512. QString cfgName = QString("panel%1").arg(QString::number(i));
  513. if (!getConfigValue(cfgName).isNull()) {
  514. QString name = QString(" Panel %1").arg(QString::number(i));
  515. QListWidgetItem* panelItem = new QListWidgetItem(name);
  516. panelItem->setIcon(QIcon::fromTheme("cs-applets"));
  517. panelsListWidget->addItem(panelItem);
  518. }
  519. }
  520. saveConfig();
  521. });
  522. connect(removePanelButton, &QPushButton::clicked, this, [this, panelsListWidget]() {
  523. if (!panelsListWidget->selectedItems().isEmpty() && panelsListWidget->count() > 1) {
  524. QMessageBox msgBox(this);
  525. msgBox.setWindowTitle("Removing panel");
  526. msgBox.setText("Are you sure you want to remove selected panel? "
  527. "This action cannot be undone.");
  528. msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  529. msgBox.setIcon(QMessageBox::Question);
  530. if (msgBox.exec() == QMessageBox::Yes) {
  531. int panelID = panelsListWidget->currentItem()->text().split(' ').last().toInt();
  532. QString panelName = QString("panel%1").arg(QString::number(panelID));
  533. setEntry(panelName, QJsonValue::Null);
  534. panelsListWidget->clear();
  535. for (int i = 1; i <= getConfigValue("countPanels").toInt(); ++i) {
  536. QString cfgName = QString("panel%1").arg(QString::number(i));
  537. if (!getConfigValue(cfgName).isNull()) {
  538. QString name = QString(" Panel %1").arg(QString::number(i));
  539. QListWidgetItem* panelItem = new QListWidgetItem(name);
  540. panelItem->setIcon(QIcon::fromTheme("cs-applets"));
  541. panelsListWidget->addItem(panelItem);
  542. }
  543. }
  544. saveConfig();
  545. }
  546. }
  547. });
  548. finalizeUI();
  549. }
  550. void PanelsPane::setPanelSettings(int panelID,
  551. QListWidget* appletsListWidget,
  552. QCheckBox* enableAutoHideCheckBox,
  553. QSpinBox* autoHideIntervalSpinBox,
  554. QSpinBox* thicknessSpinBox,
  555. QComboBox* screenComboBox,
  556. QCheckBox* stretchCheckBox,
  557. QCheckBox* setOnCenterCheckBox,
  558. QSpinBox* shiftSpinBox,
  559. QRadioButton* topRadioButton,
  560. QRadioButton* bottomRadioButton,
  561. QRadioButton* leftRadioButton,
  562. QRadioButton* rightRadioButton,
  563. QSpinBox* launcherIconSize,
  564. QLineEdit* bgrImgPathLineEdit,
  565. QSpinBox* spacingSpinBox,
  566. QSpinBox* marginSpinBox,
  567. QDoubleSpinBox* opacitySpinBox) {
  568. QString panelName = QString("panel%1").arg(QString::number(panelID));
  569. // Applets
  570. appletsListWidget->clear();
  571. QJsonArray appletsList = getConfigValue(panelName, "applets").toArray();
  572. foreach (QJsonValue applet, appletsList) {
  573. if (applet.toString().startsWith("launcher")) {
  574. QListWidgetItem* item = new QListWidgetItem();
  575. QString launcherData = applet.toString();
  576. if (launcherData.endsWith(".desktop")) {
  577. // Desktop Entry
  578. QString entry = launcherData.split(':').at(1);
  579. if (QFile::exists("/usr/share/applications/" + entry)) {
  580. entry = "/usr/share/applications/" + entry;
  581. }
  582. else {
  583. QString homeDir = QDir::homePath();
  584. entry = homeDir + "/.local/share/applications/" + entry;
  585. }
  586. QString iconPath;
  587. QSettings desktopFileReader(entry, QSettings::IniFormat);
  588. desktopFileReader.sync();
  589. desktopFileReader.beginGroup("Desktop Entry");
  590. iconPath = desktopFileReader.value("Icon").toString();
  591. desktopFileReader.endGroup();
  592. item->setText(applet.toString());
  593. if (QIcon::hasThemeIcon(iconPath)) {
  594. item->setIcon(QIcon::fromTheme(iconPath));
  595. }
  596. else if (QFile::exists(iconPath)) {
  597. item->setIcon(QIcon(iconPath));
  598. }
  599. else {
  600. item->setIcon(QIcon::fromTheme("dialog-question"));
  601. }
  602. }
  603. else {
  604. // Arbitrary executable
  605. QString iconPath = launcherData.split(':')[2];
  606. if (QIcon::hasThemeIcon(iconPath)) {
  607. item->setIcon(QIcon::fromTheme(iconPath));
  608. }
  609. else if (QFile::exists(iconPath)) {
  610. item->setIcon(QIcon(iconPath));
  611. }
  612. else {
  613. item->setIcon(QIcon::fromTheme("dialog-question"));
  614. }
  615. item->setText(applet.toString());
  616. }
  617. appletsListWidget->addItem(item);
  618. }
  619. else if (applet.toString().startsWith("clioutput")) {
  620. QListWidgetItem* item = new QListWidgetItem(applet.toString());
  621. item->setIcon(QIcon::fromTheme(mIconNameByApplet["clioutput"]));
  622. appletsListWidget->addItem(item);
  623. }
  624. else { // All other applets
  625. QString text = mAppletHumanNames[applet.toString()];
  626. QListWidgetItem* item = new QListWidgetItem(text);
  627. item->setIcon(QIcon::fromTheme(mIconNameByApplet[applet.toString()]));
  628. appletsListWidget->addItem(item);
  629. }
  630. }
  631. // Auto Hide
  632. enableAutoHideCheckBox->setChecked(getConfigValue(panelName, "enableAutoHide").toBool());
  633. autoHideIntervalSpinBox->setValue(getConfigValue(panelName, "autoHideInterval").toInt());
  634. if (enableAutoHideCheckBox->isChecked()) {
  635. autoHideIntervalSpinBox->setEnabled(true);
  636. }
  637. else {
  638. autoHideIntervalSpinBox->setEnabled(false);
  639. }
  640. // Thickness
  641. thicknessSpinBox->setValue(getConfigValue(panelName, "thickness").toInt());
  642. // Screen
  643. QString screen = getConfigValue(panelName, "screen").toString();
  644. int index = screenComboBox->findText(screen);
  645. if (index != -1) {
  646. screenComboBox->setCurrentIndex(index);
  647. }
  648. else {
  649. screenComboBox->setCurrentIndex(0);
  650. }
  651. // Stretch to the screen size
  652. stretchCheckBox->setChecked(getConfigValue(panelName, "expand").toBool());
  653. // Set On Center
  654. setOnCenterCheckBox->setChecked(getConfigValue(panelName, "setOnCenter").toBool());
  655. if (!stretchCheckBox->isChecked()) {
  656. setOnCenterCheckBox->setEnabled(true);
  657. }
  658. else {
  659. setOnCenterCheckBox->setEnabled(false);
  660. setOnCenterCheckBox->setChecked(false);
  661. }
  662. // Axis shift
  663. shiftSpinBox->setValue(getConfigValue(panelName, "shift").toInt());
  664. // Location
  665. QString location = getConfigValue(panelName, "location").toString();
  666. if (!location.compare("top")) {
  667. topRadioButton->setChecked(true);
  668. }
  669. else if (!location.compare("bottom")) {
  670. bottomRadioButton->setChecked(true);
  671. }
  672. else if (!location.compare("left")) {
  673. leftRadioButton->setChecked(true);
  674. }
  675. else if (!location.compare("right")) {
  676. rightRadioButton->setChecked(true);
  677. }
  678. else { // Unknown option
  679. topRadioButton->setChecked(true);
  680. }
  681. // Launcher Icon Size
  682. launcherIconSize->setValue(getConfigValue(panelName, "launcherIconSize").toInt());
  683. // Background Image
  684. bgrImgPathLineEdit->setText(getConfigValue(panelName, "backgroundImage").toString());
  685. // Spacing
  686. spacingSpinBox->setValue(getConfigValue(panelName, "spacing").toInt());
  687. // Margin
  688. marginSpinBox->setValue(getConfigValue(panelName, "margin").toInt());
  689. // Opacity
  690. opacitySpinBox->setValue(getConfigValue(panelName, "opacity").toDouble());
  691. mSaveButton->setVisible(false);
  692. }
  693. void PanelsPane::prepareToSave(int panelID,
  694. QListWidget* appletsListWidget,
  695. QCheckBox* enableAutoHideCheckBox,
  696. QSpinBox* autoHideIntervalSpinBox,
  697. QSpinBox* thicknessSpinBox,
  698. QComboBox* screenComboBox,
  699. QCheckBox* stretchCheckBox,
  700. QCheckBox* setOnCenterCheckBox,
  701. QSpinBox* shiftSpinBox,
  702. QRadioButton* topRadioButton,
  703. QRadioButton* bottomRadioButton,
  704. QRadioButton* leftRadioButton,
  705. QRadioButton* rightRadioButton,
  706. QSpinBox* launcherIconSizeSpinBox,
  707. QLineEdit* bgrImgPathLineEdit,
  708. QSpinBox* spacingSpinBox,
  709. QSpinBox* marginSpinBox,
  710. QDoubleSpinBox* opacitySpinBox) {
  711. QJsonObject panelObject;
  712. // Applets
  713. QJsonArray applets;
  714. for (int i = 0; i < appletsListWidget->count(); ++i) {
  715. QListWidgetItem* item = appletsListWidget->item(i);
  716. QString itemName = item->text();
  717. QString finalName;
  718. if (itemName.startsWith("launcher:") || itemName.startsWith("clioutput:")) {
  719. finalName = itemName;
  720. }
  721. else { // All other applets
  722. finalName = mAppletHumanNames.key(itemName);
  723. }
  724. applets.append(QJsonValue(finalName));
  725. }
  726. panelObject["applets"] = QJsonValue(applets);
  727. // Auto Hide
  728. panelObject["enableAutoHide"] = QJsonValue(enableAutoHideCheckBox->isChecked());
  729. panelObject["autoHideInterval"] = QJsonValue(autoHideIntervalSpinBox->value());
  730. // Thickness
  731. panelObject["thickness"] = QJsonValue(thicknessSpinBox->value());
  732. // Screen
  733. if (screenComboBox->currentIndex() == 0) { // (primary screen)
  734. panelObject["screen"] = QJsonValue("");
  735. }
  736. else {
  737. panelObject["screen"] = QJsonValue(screenComboBox->currentText());
  738. }
  739. // Stretch
  740. panelObject["expand"] = QJsonValue(stretchCheckBox->isChecked());
  741. // Set On Center
  742. panelObject["setOnCenter"] = QJsonValue(setOnCenterCheckBox->isChecked());
  743. // Axis shift
  744. panelObject["shift"] = QJsonValue(shiftSpinBox->value());
  745. // Location
  746. QString location;
  747. if (topRadioButton->isChecked()) {
  748. location = "top";
  749. }
  750. else if (bottomRadioButton->isChecked()) {
  751. location = "bottom";
  752. }
  753. else if (leftRadioButton->isChecked()) {
  754. location = "left";
  755. }
  756. else if (rightRadioButton->isChecked()) {
  757. location = "right";
  758. }
  759. else {
  760. location = "top";
  761. }
  762. panelObject["location"] = QJsonValue(location);
  763. // Launcher Icon Size
  764. panelObject["launcherIconSize"] = QJsonValue(launcherIconSizeSpinBox->value());
  765. // Background Image
  766. panelObject["backgroundImage"] = QJsonValue(bgrImgPathLineEdit->text());
  767. // Spacing
  768. panelObject["spacing"] = QJsonValue(spacingSpinBox->value());
  769. // Margin
  770. panelObject["margin"] = QJsonValue(marginSpinBox->value());
  771. // Opacity
  772. panelObject["opacity"] = QJsonValue(opacitySpinBox->value());
  773. QString panelName = QString("panel%1").arg(QString::number(panelID));
  774. setEntry(panelName, panelObject);
  775. }
  776. PanelsPane::PanelsPane(QJsonObject* cfgObj) : Pane(nullptr,
  777. cfgObj,
  778. tr("Panels"),
  779. "cs-applets") {
  780. mAppletHumanNames["appmenu"] = tr("App Menu");
  781. mAppletHumanNames["datetime"] = tr("Date & Time");
  782. mAppletHumanNames["kblayout"] = tr("Keyboard Layout");
  783. mAppletHumanNames["localipv4"] = tr("Local IPv4 Address");
  784. mAppletHumanNames["battery"] = tr("Battery");
  785. mAppletHumanNames["sni"] = tr("Tray (StatusNotifierItem)");
  786. mAppletHumanNames["mpris"] = tr("Playback Control (MPRIS)");
  787. mAppletHumanNames["usermenu"] = tr("User Menu");
  788. mAppletHumanNames["volume"] = tr("Volume");
  789. mAppletHumanNames["windowlist"] = tr("Window List");
  790. mAppletHumanNames["workspaces"] = tr("Workspaces");
  791. mAppletHumanNames["spacer"] = tr("Spacer");
  792. mAppletHumanNames["splitter"] = tr("Splitter");
  793. mIconNameByApplet["appmenu"] = "app-launcher";
  794. mIconNameByApplet["datetime"] = "calendar";
  795. mIconNameByApplet["kblayout"] = "keyboard";
  796. mIconNameByApplet["localipv4"] = "cs-network";
  797. mIconNameByApplet["battery"] = "extensions";
  798. mIconNameByApplet["sni"] = "extensions";
  799. mIconNameByApplet["mpris"] = "preferences-system-sound";
  800. mIconNameByApplet["usermenu"] = "preferences-desktop-user";
  801. mIconNameByApplet["volume"] = "preferences-system-sound";
  802. mIconNameByApplet["windowlist"] = "preferences-system-windows";
  803. mIconNameByApplet["workspaces"] = "workspace-switcher-top-left";
  804. mIconNameByApplet["spacer"] = "extensions";
  805. mIconNameByApplet["splitter"] = "extensions";
  806. mIconNameByApplet["launcher"] = "utilities-terminal";
  807. mIconNameByApplet["clioutput"] = "utilities-terminal";
  808. }