mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 12:30:04 +00:00 
			
		
		
		
	Alert dialog initial commit
This commit is contained in:
		
							parent
							
								
									612874f830
								
							
						
					
					
						commit
						b24acb7642
					
				
					 10 changed files with 352 additions and 5 deletions
				
			
		
							
								
								
									
										110
									
								
								scwx-qt/source/scwx/qt/ui/alert_dialog.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										110
									
								
								scwx-qt/source/scwx/qt/ui/alert_dialog.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,110 @@ | |||
| #include "alert_dialog.hpp" | ||||
| #include "ui_alert_dialog.h" | ||||
| 
 | ||||
| #include <scwx/qt/manager/text_event_manager.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::ui::alert_dialog"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class AlertDialogImpl | ||||
| { | ||||
| public: | ||||
|    explicit AlertDialogImpl(AlertDialog* self) : | ||||
|        self_ {self}, key_ {}, coordinate_ {}, currentIndex_ {0u} | ||||
|    { | ||||
|    } | ||||
|    ~AlertDialogImpl() = default; | ||||
| 
 | ||||
|    void ConnectSignals(); | ||||
|    void SelectIndex(size_t newIndex); | ||||
| 
 | ||||
|    AlertDialog*        self_; | ||||
|    types::TextEventKey key_; | ||||
|    common::Coordinate  coordinate_; | ||||
|    size_t              currentIndex_; | ||||
| }; | ||||
| 
 | ||||
| AlertDialog::AlertDialog(QWidget* parent) : | ||||
|     QDialog(parent), | ||||
|     p {std::make_unique<AlertDialogImpl>(this)}, | ||||
|     ui(new Ui::AlertDialog) | ||||
| { | ||||
|    ui->setupUi(this); | ||||
| 
 | ||||
|    // Set monospace font for alert view
 | ||||
|    QFont monospaceFont("?"); | ||||
|    monospaceFont.setStyleHint(QFont::TypeWriter); | ||||
|    ui->alertText->setFont(monospaceFont); | ||||
| 
 | ||||
|    // Add Go button to button box
 | ||||
|    ui->buttonBox->addButton("&Go", QDialogButtonBox::ActionRole); | ||||
| 
 | ||||
|    p->ConnectSignals(); | ||||
| } | ||||
| 
 | ||||
| AlertDialog::~AlertDialog() | ||||
| { | ||||
|    delete ui; | ||||
| } | ||||
| 
 | ||||
| void AlertDialogImpl::ConnectSignals() {} | ||||
| 
 | ||||
| bool AlertDialog::SelectAlert(const types::TextEventKey& key, | ||||
|                               const common::Coordinate&  coordinate) | ||||
| { | ||||
|    p->key_        = key; | ||||
|    p->coordinate_ = coordinate; | ||||
| 
 | ||||
|    setWindowTitle(QString::fromStdString(key.ToFullString())); | ||||
| 
 | ||||
|    auto messages = manager::TextEventManager::Instance().message_list(key); | ||||
|    if (messages.empty()) | ||||
|    { | ||||
|       return false; | ||||
|    } | ||||
| 
 | ||||
|    p->SelectIndex(messages.size() - 1); | ||||
| 
 | ||||
|    return true; | ||||
| } | ||||
| 
 | ||||
| void AlertDialogImpl::SelectIndex(size_t newIndex) | ||||
| { | ||||
|    size_t messageCount = | ||||
|       manager::TextEventManager::Instance().message_count(key_); | ||||
| 
 | ||||
|    if (newIndex >= messageCount) | ||||
|    { | ||||
|       return; | ||||
|    } | ||||
| 
 | ||||
|    auto messages = manager::TextEventManager::Instance().message_list(key_); | ||||
| 
 | ||||
|    currentIndex_ = newIndex; | ||||
| 
 | ||||
|    self_->ui->alertText->setText( | ||||
|       QString::fromStdString(messages[currentIndex_]->message_content())); | ||||
|    self_->ui->messageCountLabel->setText( | ||||
|       QObject::tr("%1 of %2").arg(currentIndex_ + 1).arg(messageCount)); | ||||
| 
 | ||||
|    bool firstSelected = (currentIndex_ == 0); | ||||
|    bool lastSelected  = (currentIndex_ == messages.size() - 1); | ||||
| 
 | ||||
|    self_->ui->firstButton->setEnabled(!firstSelected); | ||||
|    self_->ui->previousButton->setEnabled(!firstSelected); | ||||
| 
 | ||||
|    self_->ui->nextButton->setEnabled(!lastSelected); | ||||
|    self_->ui->lastButton->setEnabled(!lastSelected); | ||||
| } | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										44
									
								
								scwx-qt/source/scwx/qt/ui/alert_dialog.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								scwx-qt/source/scwx/qt/ui/alert_dialog.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,44 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <QDialog> | ||||
| 
 | ||||
| #include <scwx/qt/types/text_event_key.hpp> | ||||
| #include <scwx/common/geographic.hpp> | ||||
| 
 | ||||
| namespace Ui | ||||
| { | ||||
| class AlertDialog; | ||||
| } | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| class AlertDialogImpl; | ||||
| 
 | ||||
| class AlertDialog : public QDialog | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit AlertDialog(QWidget* parent = nullptr); | ||||
|    ~AlertDialog(); | ||||
| 
 | ||||
|    bool SelectAlert(const types::TextEventKey& key, | ||||
|                     const common::Coordinate&  coordinate); | ||||
| 
 | ||||
| signals: | ||||
|    void MoveMap(double latitude, double longitude); | ||||
| 
 | ||||
| private: | ||||
|    friend class AlertDialogImpl; | ||||
|    std::unique_ptr<AlertDialogImpl> p; | ||||
|    Ui::AlertDialog*                 ui; | ||||
| }; | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										173
									
								
								scwx-qt/source/scwx/qt/ui/alert_dialog.ui
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										173
									
								
								scwx-qt/source/scwx/qt/ui/alert_dialog.ui
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,173 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <ui version="4.0"> | ||||
|  <class>AlertDialog</class> | ||||
|  <widget class="QDialog" name="AlertDialog"> | ||||
|   <property name="geometry"> | ||||
|    <rect> | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>540</width> | ||||
|     <height>600</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="windowTitle"> | ||||
|    <string>Dialog</string> | ||||
|   </property> | ||||
|   <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|    <item> | ||||
|     <widget class="QTextBrowser" name="alertText"> | ||||
|      <property name="lineWrapMode"> | ||||
|       <enum>QTextEdit::NoWrap</enum> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QFrame" name="frame"> | ||||
|      <property name="frameShape"> | ||||
|       <enum>QFrame::StyledPanel</enum> | ||||
|      </property> | ||||
|      <property name="frameShadow"> | ||||
|       <enum>QFrame::Raised</enum> | ||||
|      </property> | ||||
|      <layout class="QHBoxLayout" name="horizontalLayout"> | ||||
|       <property name="leftMargin"> | ||||
|        <number>0</number> | ||||
|       </property> | ||||
|       <property name="topMargin"> | ||||
|        <number>0</number> | ||||
|       </property> | ||||
|       <property name="rightMargin"> | ||||
|        <number>0</number> | ||||
|       </property> | ||||
|       <property name="bottomMargin"> | ||||
|        <number>0</number> | ||||
|       </property> | ||||
|       <item> | ||||
|        <widget class="QToolButton" name="firstButton"> | ||||
|         <property name="toolTip"> | ||||
|          <string>First</string> | ||||
|         </property> | ||||
|         <property name="text"> | ||||
|          <string>...</string> | ||||
|         </property> | ||||
|         <property name="icon"> | ||||
|          <iconset resource="../../../../scwx-qt.qrc"> | ||||
|           <normaloff>:/res/icons/font-awesome-6/backward-step-solid.svg</normaloff>:/res/icons/font-awesome-6/backward-step-solid.svg</iconset> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QToolButton" name="previousButton"> | ||||
|         <property name="toolTip"> | ||||
|          <string>Previous</string> | ||||
|         </property> | ||||
|         <property name="text"> | ||||
|          <string>...</string> | ||||
|         </property> | ||||
|         <property name="icon"> | ||||
|          <iconset resource="../../../../scwx-qt.qrc"> | ||||
|           <normaloff>:/res/icons/font-awesome-6/angle-left-solid.svg</normaloff>:/res/icons/font-awesome-6/angle-left-solid.svg</iconset> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QToolButton" name="nextButton"> | ||||
|         <property name="toolTip"> | ||||
|          <string>Next</string> | ||||
|         </property> | ||||
|         <property name="text"> | ||||
|          <string>...</string> | ||||
|         </property> | ||||
|         <property name="icon"> | ||||
|          <iconset resource="../../../../scwx-qt.qrc"> | ||||
|           <normaloff>:/res/icons/font-awesome-6/angle-right-solid.svg</normaloff>:/res/icons/font-awesome-6/angle-right-solid.svg</iconset> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QToolButton" name="lastButton"> | ||||
|         <property name="toolTip"> | ||||
|          <string>Last</string> | ||||
|         </property> | ||||
|         <property name="text"> | ||||
|          <string>...</string> | ||||
|         </property> | ||||
|         <property name="icon"> | ||||
|          <iconset resource="../../../../scwx-qt.qrc"> | ||||
|           <normaloff>:/res/icons/font-awesome-6/forward-step-solid.svg</normaloff>:/res/icons/font-awesome-6/forward-step-solid.svg</iconset> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QLabel" name="messageCountLabel"> | ||||
|         <property name="text"> | ||||
|          <string># of #</string> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item> | ||||
|        <spacer name="horizontalSpacer"> | ||||
|         <property name="orientation"> | ||||
|          <enum>Qt::Horizontal</enum> | ||||
|         </property> | ||||
|         <property name="sizeHint" stdset="0"> | ||||
|          <size> | ||||
|           <width>40</width> | ||||
|           <height>20</height> | ||||
|          </size> | ||||
|         </property> | ||||
|        </spacer> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QDialogButtonBox" name="buttonBox"> | ||||
|         <property name="orientation"> | ||||
|          <enum>Qt::Horizontal</enum> | ||||
|         </property> | ||||
|         <property name="standardButtons"> | ||||
|          <set>QDialogButtonBox::Close</set> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|      </layout> | ||||
|     </widget> | ||||
|    </item> | ||||
|   </layout> | ||||
|  </widget> | ||||
|  <resources> | ||||
|   <include location="../../../../scwx-qt.qrc"/> | ||||
|  </resources> | ||||
|  <connections> | ||||
|   <connection> | ||||
|    <sender>buttonBox</sender> | ||||
|    <signal>accepted()</signal> | ||||
|    <receiver>AlertDialog</receiver> | ||||
|    <slot>accept()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>248</x> | ||||
|      <y>254</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>157</x> | ||||
|      <y>274</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|   <connection> | ||||
|    <sender>buttonBox</sender> | ||||
|    <signal>rejected()</signal> | ||||
|    <receiver>AlertDialog</receiver> | ||||
|    <slot>reject()</slot> | ||||
|    <hints> | ||||
|     <hint type="sourcelabel"> | ||||
|      <x>316</x> | ||||
|      <y>260</y> | ||||
|     </hint> | ||||
|     <hint type="destinationlabel"> | ||||
|      <x>286</x> | ||||
|      <y>274</y> | ||||
|     </hint> | ||||
|    </hints> | ||||
|   </connection> | ||||
|  </connections> | ||||
| </ui> | ||||
|  | @ -4,6 +4,7 @@ | |||
| #include <scwx/qt/manager/text_event_manager.hpp> | ||||
| #include <scwx/qt/model/alert_model.hpp> | ||||
| #include <scwx/qt/types/qt_types.hpp> | ||||
| #include <scwx/qt/ui/alert_dialog.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <QSortFilterProxyModel> | ||||
|  | @ -26,6 +27,7 @@ public: | |||
|        self_ {self}, | ||||
|        alertModel_ {std::make_unique<model::AlertModel>()}, | ||||
|        proxyModel_ {std::make_unique<QSortFilterProxyModel>()}, | ||||
|        alertDialog_ {new AlertDialog(self)}, | ||||
|        mapPosition_ {}, | ||||
|        mapUpdateDeferred_ {false}, | ||||
|        selectedAlertKey_ {}, | ||||
|  | @ -44,6 +46,8 @@ public: | |||
|    std::unique_ptr<model::AlertModel>     alertModel_; | ||||
|    std::unique_ptr<QSortFilterProxyModel> proxyModel_; | ||||
| 
 | ||||
|    AlertDialog* alertDialog_; | ||||
| 
 | ||||
|    scwx::common::Coordinate mapPosition_; | ||||
|    bool                     mapUpdateDeferred_; | ||||
| 
 | ||||
|  | @ -151,9 +155,12 @@ void AlertDockWidgetImpl::ConnectSignals() | |||
|    connect(self_->ui->alertViewButton, | ||||
|            &QPushButton::clicked, | ||||
|            this, | ||||
|            []() | ||||
|            [=]() | ||||
|            { | ||||
|               // TODO: View alert
 | ||||
|               // View alert
 | ||||
|               alertDialog_->SelectAlert(selectedAlertKey_, | ||||
|                                         selectedAlertCentroid_); | ||||
|               alertDialog_->show(); | ||||
|            }); | ||||
|    connect(self_->ui->alertGoButton, | ||||
|            &QPushButton::clicked, | ||||
|  | @ -163,6 +170,8 @@ void AlertDockWidgetImpl::ConnectSignals() | |||
|               emit self_->MoveMap(selectedAlertCentroid_.latitude_, | ||||
|                                   selectedAlertCentroid_.longitude_); | ||||
|            }); | ||||
|    connect( | ||||
|       alertDialog_, &AlertDialog::MoveMap, self_, &AlertDockWidget::MoveMap); | ||||
| } | ||||
| 
 | ||||
| #include "alert_dock_widget.moc" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat