|
8 | 8 |
|
9 | 9 | #include "include/ui/widget/TrayOtpCodes.hpp" |
10 | 10 | #include "include/ui/widget/TrayProfileSelector.hpp" |
| 11 | +#include "include/ui/widget/RoutingQuickMenu.hpp" |
| 12 | +#include "include/ui/setting/RouteItem.h" |
11 | 13 |
|
12 | 14 | void MainWindow::trayClickEvent() { |
13 | 15 | constexpr qint64 recentlyActiveMs = 350; |
@@ -178,6 +180,101 @@ void MainWindow::openTrayOtpCodes() { |
178 | 180 | trayOtpCodes->popupAt(QCursor::pos()); |
179 | 181 | } |
180 | 182 |
|
| 183 | +void MainWindow::on_toolButton_link1_clicked() { |
| 184 | + const auto &url = Configs::dataManager->settingsRepo->quick_link_1; |
| 185 | + if (url.isEmpty()) { |
| 186 | + QMessageBox::information(this, "Quick Link 1", "Set the URL in Settings → Basic Settings → Quick Links."); |
| 187 | + return; |
| 188 | + } |
| 189 | + QDesktopServices::openUrl(QUrl(url)); |
| 190 | +} |
| 191 | + |
| 192 | +void MainWindow::on_toolButton_link2_clicked() { |
| 193 | + const auto &url = Configs::dataManager->settingsRepo->quick_link_2; |
| 194 | + if (url.isEmpty()) { |
| 195 | + QMessageBox::information(this, "Quick Link 2", "Set the URL in Settings → Basic Settings → Quick Links."); |
| 196 | + return; |
| 197 | + } |
| 198 | + QDesktopServices::openUrl(QUrl(url)); |
| 199 | +} |
| 200 | + |
| 201 | +void MainWindow::on_toolButton_link3_clicked() { |
| 202 | + const auto &url = Configs::dataManager->settingsRepo->quick_link_3; |
| 203 | + if (url.isEmpty()) { |
| 204 | + QMessageBox::information(this, "Quick Link 3", "Set the URL in Settings → Basic Settings → Quick Links."); |
| 205 | + return; |
| 206 | + } |
| 207 | + QDesktopServices::openUrl(QUrl(url)); |
| 208 | +} |
| 209 | + |
| 210 | +void MainWindow::refreshRoutingStatus() { |
| 211 | + if (auto *label = findChild<QLabel *>(QStringLiteral("routingStatus"))) |
| 212 | + setStatusText(label, RoutingQuickMenu::statusSummary()); |
| 213 | +} |
| 214 | + |
| 215 | +void MainWindow::openRoutingQuickMenu(const QPoint &globalPos) { |
| 216 | + if (routingQuickMenu) routingQuickMenu->close(); |
| 217 | + |
| 218 | + // Applying a routing change means regenerating the config, so a running |
| 219 | + // profile has to be restarted for it to take effect. |
| 220 | + const auto applyToRunningProfile = [this] { |
| 221 | + refreshRoutingStatus(); |
| 222 | + if (Configs::dataManager->settingsRepo->started_id >= 0) |
| 223 | + profile_start(Configs::dataManager->settingsRepo->started_id); |
| 224 | + }; |
| 225 | + const auto withActiveProfile = [applyToRunningProfile](const std::function<void(Configs::RouteProfile &)> &change) { |
| 226 | + auto profile = Configs::dataManager->routesRepo->GetRouteProfile( |
| 227 | + Configs::dataManager->settingsRepo->current_route_id); |
| 228 | + if (!profile) return; |
| 229 | + change(*profile); |
| 230 | + Configs::dataManager->routesRepo->Save(profile); |
| 231 | + applyToRunningProfile(); |
| 232 | + }; |
| 233 | + |
| 234 | + RoutingQuickMenu::Callbacks cb; |
| 235 | + cb.setDefaultOutbound = [withActiveProfile](int outboundID) { |
| 236 | + withActiveProfile([outboundID](Configs::RouteProfile &profile) { profile.defaultOutboundID = outboundID; }); |
| 237 | + }; |
| 238 | + cb.setApplyProfileRules = [withActiveProfile](bool enabled) { |
| 239 | + withActiveProfile([enabled](Configs::RouteProfile &profile) { profile.applyProfileRules = enabled; }); |
| 240 | + }; |
| 241 | + cb.openProfile = [this, applyToRunningProfile] { |
| 242 | + auto profile = Configs::dataManager->routesRepo->GetRouteProfile( |
| 243 | + Configs::dataManager->settingsRepo->current_route_id); |
| 244 | + // Raw profiles have their own editor; the structured one cannot show them. |
| 245 | + if (!profile || profile->isRaw) { |
| 246 | + on_menu_routing_settings_triggered(); |
| 247 | + return; |
| 248 | + } |
| 249 | + if (dialog_is_using) return; |
| 250 | + dialog_is_using = true; |
| 251 | + auto *editor = new RouteItem(this, profile); |
| 252 | + connect(editor, &RouteItem::settingsChanged, this, |
| 253 | + [applyToRunningProfile](const std::shared_ptr<Configs::RouteProfile> &edited) { |
| 254 | + Configs::dataManager->routesRepo->Save(edited); |
| 255 | + applyToRunningProfile(); |
| 256 | + }); |
| 257 | + connect(editor, &QDialog::finished, this, [this, editor] { |
| 258 | + editor->deleteLater(); |
| 259 | + dialog_is_using = false; |
| 260 | + }); |
| 261 | + editor->show(); |
| 262 | + }; |
| 263 | + cb.manageProfiles = [this] { on_menu_routing_settings_triggered(); }; |
| 264 | + |
| 265 | + routingQuickMenu = new RoutingQuickMenu(cb, this); |
| 266 | + routingQuickMenu->popupAt(globalPos); |
| 267 | +} |
| 268 | + |
| 269 | +void MainWindow::refreshQuickLinkButtons() { |
| 270 | + auto *btn1 = findChild<QToolButton*>("linkBtn1"); |
| 271 | + auto *btn2 = findChild<QToolButton*>("linkBtn2"); |
| 272 | + auto *btn3 = findChild<QToolButton*>("linkBtn3"); |
| 273 | + if (btn1) btn1->setText(Configs::dataManager->settingsRepo->quick_link_name_1.isEmpty() ? tr("Link 1") : Configs::dataManager->settingsRepo->quick_link_name_1); |
| 274 | + if (btn2) btn2->setText(Configs::dataManager->settingsRepo->quick_link_name_2.isEmpty() ? tr("Link 2") : Configs::dataManager->settingsRepo->quick_link_name_2); |
| 275 | + if (btn3) btn3->setText(Configs::dataManager->settingsRepo->quick_link_name_3.isEmpty() ? tr("Link 3") : Configs::dataManager->settingsRepo->quick_link_name_3); |
| 276 | +} |
| 277 | + |
181 | 278 | void MainWindow::keyPressEvent(QKeyEvent *event) { |
182 | 279 | if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { |
183 | 280 | if (!qobject_cast<QLineEdit *>(QApplication::focusWidget())) { |
@@ -208,6 +305,12 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { |
208 | 305 | } else if (obj == ui->tabWidget && mouseEvent->button() == Qt::RightButton) { |
209 | 306 | on_tabWidget_customContextMenuRequested(mouseEvent->position().toPoint()); |
210 | 307 | return true; |
| 308 | + } else if (mouseEvent->button() == Qt::LeftButton) { |
| 309 | + if (auto *segment = qobject_cast<QFrame *>(obj); |
| 310 | + segment && segment->objectName() == QStringLiteral("routingStatusButton")) { |
| 311 | + openRoutingQuickMenu(segment->mapToGlobal(QPoint(segment->width() / 2, 0))); |
| 312 | + return true; |
| 313 | + } |
211 | 314 | } |
212 | 315 | } else if (type == QEvent::MouseButtonDblClick) { |
213 | 316 | if (obj == ui->splitter) { |
|
0 commit comments