diff options
Diffstat (limited to 'UDPExamples/MessageAggregatorMainWindow.cpp')
| -rw-r--r-- | UDPExamples/MessageAggregatorMainWindow.cpp | 131 |
1 files changed, 124 insertions, 7 deletions
diff --git a/UDPExamples/MessageAggregatorMainWindow.cpp b/UDPExamples/MessageAggregatorMainWindow.cpp index 196282d6..1d1dce5d 100644 --- a/UDPExamples/MessageAggregatorMainWindow.cpp +++ b/UDPExamples/MessageAggregatorMainWindow.cpp @@ -22,17 +22,25 @@ namespace QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Sent"), QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Rec'd"), QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Power"), + QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Operator"), + QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "My Call"), + QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "My Grid"), QT_TRANSLATE_NOOP ("MessageAggregatorMainWindow", "Comments"), }; } MessageAggregatorMainWindow::MessageAggregatorMainWindow () - : log_ {new QStandardItemModel {0, 11, this}} + : log_ {new QStandardItemModel {0, 14, this}} , decodes_model_ {new DecodesModel {this}} , beacons_model_ {new BeaconsModel {this}} , server_ {new MessageServer {this}} , multicast_group_line_edit_ {new QLineEdit} , log_table_view_ {new QTableView} + , add_call_of_interest_action_ {new QAction {tr ("&Add callsign"), this}} + , delete_call_of_interest_action_ {new QAction {tr ("&Delete callsign"), this}} + , last_call_of_interest_action_ {new QAction {tr ("&Highlight last only"), this}} + , call_of_interest_bg_colour_action_ {new QAction {tr ("&Background colour"), this}} + , call_of_interest_fg_colour_action_ {new QAction {tr ("&Foreground colour"), this}} { // logbook int column {0}; @@ -80,6 +88,91 @@ MessageAggregatorMainWindow::MessageAggregatorMainWindow () setDockOptions (AnimatedDocks | AllowNestedDocks | AllowTabbedDocks); setTabPosition (Qt::BottomDockWidgetArea, QTabWidget::North); + QDockWidget * calls_dock {new QDockWidget {tr ("Calls of Interest"), this}}; + calls_dock->setAllowedAreas (Qt::RightDockWidgetArea); + calls_of_interest_ = new QListWidget {calls_dock}; + calls_of_interest_->setContextMenuPolicy (Qt::ActionsContextMenu); + calls_of_interest_->insertAction (nullptr, add_call_of_interest_action_); + connect (add_call_of_interest_action_, &QAction::triggered, [this] () { + auto item = new QListWidgetItem {}; + item->setFlags (item->flags () | Qt::ItemIsEditable); + item->setData (Qt::UserRole, QString {}); + calls_of_interest_->addItem (item); + calls_of_interest_->editItem (item); + }); + calls_of_interest_->insertAction (nullptr, delete_call_of_interest_action_); + connect (delete_call_of_interest_action_, &QAction::triggered, [this] () { + for (auto item : calls_of_interest_->selectedItems ()) + { + auto old_call = item->data (Qt::UserRole); + if (old_call.isValid ()) change_highlighting (old_call.toString ()); + delete item; + } + }); + calls_of_interest_->insertAction (nullptr, last_call_of_interest_action_); + connect (last_call_of_interest_action_, &QAction::triggered, [this] () { + for (auto item : calls_of_interest_->selectedItems ()) + { + auto old_call = item->data (Qt::UserRole); + change_highlighting (old_call.toString ()); + change_highlighting (old_call.toString () + , item->background ().color (), item->foreground ().color (), true); + delete item; + } + }); + calls_of_interest_->insertAction (nullptr, call_of_interest_bg_colour_action_); + connect (call_of_interest_bg_colour_action_, &QAction::triggered, [this] () { + for (auto item : calls_of_interest_->selectedItems ()) + { + auto old_call = item->data (Qt::UserRole); + auto new_colour = QColorDialog::getColor (item->background ().color () + , this, tr ("Select background color")); + if (new_colour.isValid ()) + { + change_highlighting (old_call.toString (), new_colour, item->foreground ().color ()); + item->setBackground (new_colour); + } + } + }); + calls_of_interest_->insertAction (nullptr, call_of_interest_fg_colour_action_); + connect (call_of_interest_fg_colour_action_, &QAction::triggered, [this] () { + for (auto item : calls_of_interest_->selectedItems ()) + { + auto old_call = item->data (Qt::UserRole); + auto new_colour = QColorDialog::getColor (item->foreground ().color () + , this, tr ("Select foreground color")); + if (new_colour.isValid ()) + { + change_highlighting (old_call.toString (), item->background ().color (), new_colour); + item->setForeground (new_colour); + } + } + }); + connect (calls_of_interest_, &QListWidget::itemChanged, [this] (QListWidgetItem * item) { + auto old_call = item->data (Qt::UserRole); + auto new_call = item->text ().toUpper (); + if (new_call != old_call) + { + // tell all clients + if (old_call.isValid ()) + { + change_highlighting (old_call.toString ()); + } + item->setData (Qt::UserRole, new_call); + item->setText (new_call); + auto bg = item->listWidget ()->palette ().text ().color (); + auto fg = item->listWidget ()->palette ().base ().color (); + item->setBackground (bg); + item->setForeground (fg); + change_highlighting (new_call, bg, fg); + } + }); + + calls_dock->setWidget (calls_of_interest_); + addDockWidget (Qt::RightDockWidgetArea, calls_dock); + view_menu_->addAction (calls_dock->toggleViewAction ()); + view_menu_->addSeparator (); + // connect up server connect (server_, &MessageServer::error, [this] (QString const& message) { QMessageBox::warning (this, QApplication::applicationName (), tr ("Network Error"), message); @@ -111,10 +204,12 @@ MessageAggregatorMainWindow::MessageAggregatorMainWindow () show (); } -void MessageAggregatorMainWindow::log_qso (QString const& /*id*/, QDateTime time_off, QString const& dx_call, QString const& dx_grid - , Frequency dial_frequency, QString const& mode, QString const& report_sent - , QString const& report_received, QString const& tx_power, QString const& comments - , QString const& name, QDateTime time_on) +void MessageAggregatorMainWindow::log_qso (QString const& /*id*/, QDateTime time_off, QString const& dx_call + , QString const& dx_grid, Frequency dial_frequency, QString const& mode + , QString const& report_sent, QString const& report_received + , QString const& tx_power, QString const& comments + , QString const& name, QDateTime time_on, QString const& operator_call + , QString const& my_call, QString const& my_grid) { QList<QStandardItem *> row; row << new QStandardItem {time_on.toString ("dd-MMM-yyyy hh:mm:ss")} @@ -127,6 +222,9 @@ void MessageAggregatorMainWindow::log_qso (QString const& /*id*/, QDateTime time << new QStandardItem {report_sent} << new QStandardItem {report_received} << new QStandardItem {tx_power} + << new QStandardItem {operator_call} + << new QStandardItem {my_call} + << new QStandardItem {my_grid} << new QStandardItem {comments}; log_->appendRow (row); log_table_view_->resizeColumnsToContents (); @@ -136,7 +234,7 @@ void MessageAggregatorMainWindow::log_qso (QString const& /*id*/, QDateTime time void MessageAggregatorMainWindow::add_client (QString const& id, QString const& version, QString const& revision) { - auto dock = new ClientWidget {decodes_model_, beacons_model_, id, version, revision, this}; + auto dock = new ClientWidget {decodes_model_, beacons_model_, id, version, revision, calls_of_interest_, this}; dock->setAttribute (Qt::WA_DeleteOnClose); auto view_action = dock->toggleViewAction (); view_action->setEnabled (true); @@ -149,9 +247,11 @@ void MessageAggregatorMainWindow::add_client (QString const& id, QString const& connect (dock, &ClientWidget::do_reply, decodes_model_, &DecodesModel::do_reply); connect (dock, &ClientWidget::do_halt_tx, server_, &MessageServer::halt_tx); connect (dock, &ClientWidget::do_free_text, server_, &MessageServer::free_text); + connect (dock, &ClientWidget::location, server_, &MessageServer::location); connect (view_action, &QAction::toggled, dock, &ClientWidget::setVisible); + connect (dock, &ClientWidget::highlight_callsign, server_, &MessageServer::highlight_callsign); dock_widgets_[id] = dock; - server_->replay (id); + server_->replay (id); // request decodes and status } void MessageAggregatorMainWindow::remove_client (QString const& id) @@ -164,4 +264,21 @@ void MessageAggregatorMainWindow::remove_client (QString const& id) } } +MessageAggregatorMainWindow::~MessageAggregatorMainWindow () +{ + for (auto client : dock_widgets_) + { + delete client; + } +} + +void MessageAggregatorMainWindow::change_highlighting (QString const& call, QColor const& bg, QColor const& fg + , bool last_only) +{ + for (auto id : dock_widgets_.keys ()) + { + server_->highlight_callsign (id, call, bg, fg, last_only); + } +} + #include "moc_MessageAggregatorMainWindow.cpp" |
