mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 08:50:05 +00:00 
			
		
		
		
	Add open URL dialog to add a placefile
This commit is contained in:
		
							parent
							
								
									4c685e5abb
								
							
						
					
					
						commit
						157500e20a
					
				
					 5 changed files with 292 additions and 0 deletions
				
			
		
							
								
								
									
										103
									
								
								scwx-qt/source/scwx/qt/ui/open_url_dialog.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										103
									
								
								scwx-qt/source/scwx/qt/ui/open_url_dialog.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,103 @@ | |||
| #include "open_url_dialog.hpp" | ||||
| #include "ui_open_url_dialog.h" | ||||
| 
 | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| #include <QFileDialog> | ||||
| #include <QPushButton> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::ui::open_url_dialog"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class OpenUrlDialogImpl | ||||
| { | ||||
| public: | ||||
|    explicit OpenUrlDialogImpl(OpenUrlDialog* self) : self_ {self} {} | ||||
|    ~OpenUrlDialogImpl() = default; | ||||
| 
 | ||||
|    void ConnectSignals(); | ||||
|    void SelectFile(); | ||||
| 
 | ||||
|    OpenUrlDialog* self_; | ||||
| }; | ||||
| 
 | ||||
| OpenUrlDialog::OpenUrlDialog(const QString& title, QWidget* parent) : | ||||
|     QDialog(parent), | ||||
|     p {std::make_unique<OpenUrlDialogImpl>(this)}, | ||||
|     ui(new Ui::OpenUrlDialog) | ||||
| { | ||||
|    ui->setupUi(this); | ||||
| 
 | ||||
|    setWindowTitle(title); | ||||
| 
 | ||||
|    ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); | ||||
| 
 | ||||
|    p->ConnectSignals(); | ||||
| } | ||||
| 
 | ||||
| OpenUrlDialog::~OpenUrlDialog() | ||||
| { | ||||
|    delete ui; | ||||
| } | ||||
| 
 | ||||
| void OpenUrlDialogImpl::ConnectSignals() | ||||
| { | ||||
|    QObject::connect(self_->ui->urlEdit, | ||||
|                     &QLineEdit::textChanged, | ||||
|                     self_, | ||||
|                     [this](const QString& text) | ||||
|                     { | ||||
|                        QUrl url(text); | ||||
|                        self_->ui->buttonBox->button(QDialogButtonBox::Ok) | ||||
|                           ->setEnabled(url.isValid()); | ||||
|                     }); | ||||
| 
 | ||||
|    QObject::connect(self_->ui->fileButton, | ||||
|                     &QToolButton::clicked, | ||||
|                     self_, | ||||
|                     [this]() { SelectFile(); }); | ||||
| } | ||||
| 
 | ||||
| void OpenUrlDialog::showEvent(QShowEvent* event) | ||||
| { | ||||
|    ui->urlEdit->setText(QString()); | ||||
|    QDialog::showEvent(event); | ||||
| } | ||||
| 
 | ||||
| QString OpenUrlDialog::url() const | ||||
| { | ||||
|    return ui->urlEdit->text(); | ||||
| } | ||||
| 
 | ||||
| void OpenUrlDialogImpl::SelectFile() | ||||
| { | ||||
|    static const std::string placefileFilter = "Placefiles (*)"; | ||||
| 
 | ||||
|    QFileDialog* dialog = new QFileDialog(self_); | ||||
| 
 | ||||
|    dialog->setFileMode(QFileDialog::ExistingFile); | ||||
|    dialog->setNameFilter(QObject::tr(placefileFilter.c_str())); | ||||
|    dialog->setAttribute(Qt::WA_DeleteOnClose); | ||||
| 
 | ||||
|    QObject::connect(dialog, | ||||
|                     &QFileDialog::fileSelected, | ||||
|                     self_, | ||||
|                     [this](const QString& file) | ||||
|                     { | ||||
|                        logger_->debug("Selected: {}", file.toStdString()); | ||||
|                        self_->ui->urlEdit->setText(file); | ||||
|                     }); | ||||
| 
 | ||||
|    dialog->open(); | ||||
| } | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										40
									
								
								scwx-qt/source/scwx/qt/ui/open_url_dialog.hpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								scwx-qt/source/scwx/qt/ui/open_url_dialog.hpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,40 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <QDialog> | ||||
| 
 | ||||
| namespace Ui | ||||
| { | ||||
| class OpenUrlDialog; | ||||
| } | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
| { | ||||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| class OpenUrlDialogImpl; | ||||
| 
 | ||||
| class OpenUrlDialog : public QDialog | ||||
| { | ||||
|    Q_OBJECT | ||||
| 
 | ||||
| public: | ||||
|    explicit OpenUrlDialog(const QString& title, QWidget* parent = nullptr); | ||||
|    ~OpenUrlDialog(); | ||||
| 
 | ||||
|    QString url() const; | ||||
| 
 | ||||
| protected: | ||||
|    void showEvent(QShowEvent* event); | ||||
| 
 | ||||
| private: | ||||
|    friend class OpenUrlDialogImpl; | ||||
|    std::unique_ptr<OpenUrlDialogImpl> p; | ||||
|    Ui::OpenUrlDialog*                 ui; | ||||
| }; | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
							
								
								
									
										118
									
								
								scwx-qt/source/scwx/qt/ui/open_url_dialog.ui
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								scwx-qt/source/scwx/qt/ui/open_url_dialog.ui
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,118 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <ui version="4.0"> | ||||
|  <class>OpenUrlDialog</class> | ||||
|  <widget class="QDialog" name="OpenUrlDialog"> | ||||
|   <property name="geometry"> | ||||
|    <rect> | ||||
|     <x>0</x> | ||||
|     <y>0</y> | ||||
|     <width>400</width> | ||||
|     <height>80</height> | ||||
|    </rect> | ||||
|   </property> | ||||
|   <property name="windowTitle"> | ||||
|    <string>Dialog</string> | ||||
|   </property> | ||||
|   <layout class="QVBoxLayout" name="verticalLayout"> | ||||
|    <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="QLabel" name="label"> | ||||
|         <property name="text"> | ||||
|          <string>URL:</string> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QLineEdit" name="urlEdit"/> | ||||
|       </item> | ||||
|       <item> | ||||
|        <widget class="QToolButton" name="fileButton"> | ||||
|         <property name="text"> | ||||
|          <string>...</string> | ||||
|         </property> | ||||
|        </widget> | ||||
|       </item> | ||||
|      </layout> | ||||
|     </widget> | ||||
|    </item> | ||||
|    <item> | ||||
|     <spacer name="verticalSpacer"> | ||||
|      <property name="orientation"> | ||||
|       <enum>Qt::Vertical</enum> | ||||
|      </property> | ||||
|      <property name="sizeHint" stdset="0"> | ||||
|       <size> | ||||
|        <width>20</width> | ||||
|        <height>40</height> | ||||
|       </size> | ||||
|      </property> | ||||
|     </spacer> | ||||
|    </item> | ||||
|    <item> | ||||
|     <widget class="QDialogButtonBox" name="buttonBox"> | ||||
|      <property name="orientation"> | ||||
|       <enum>Qt::Horizontal</enum> | ||||
|      </property> | ||||
|      <property name="standardButtons"> | ||||
|       <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||||
|      </property> | ||||
|     </widget> | ||||
|    </item> | ||||
|   </layout> | ||||
|  </widget> | ||||
|  <resources/> | ||||
|  <connections> | ||||
|   <connection> | ||||
|    <sender>buttonBox</sender> | ||||
|    <signal>accepted()</signal> | ||||
|    <receiver>OpenUrlDialog</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>OpenUrlDialog</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> | ||||
|  | @ -1,6 +1,9 @@ | |||
| #include "placefile_settings_widget.hpp" | ||||
| #include "ui_placefile_settings_widget.h" | ||||
| 
 | ||||
| #include <scwx/qt/ui/open_url_dialog.hpp> | ||||
| #include <scwx/util/logger.hpp> | ||||
| 
 | ||||
| namespace scwx | ||||
| { | ||||
| namespace qt | ||||
|  | @ -8,6 +11,9 @@ namespace qt | |||
| namespace ui | ||||
| { | ||||
| 
 | ||||
| static const std::string logPrefix_ = "scwx::qt::ui::placefile_settings_widget"; | ||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||
| 
 | ||||
| class PlacefileSettingsWidgetImpl | ||||
| { | ||||
| public: | ||||
|  | @ -17,7 +23,10 @@ public: | |||
|    } | ||||
|    ~PlacefileSettingsWidgetImpl() = default; | ||||
| 
 | ||||
|    void ConnectSignals(); | ||||
| 
 | ||||
|    PlacefileSettingsWidget* self_; | ||||
|    OpenUrlDialog*           openUrlDialog_ {nullptr}; | ||||
| }; | ||||
| 
 | ||||
| PlacefileSettingsWidget::PlacefileSettingsWidget(QWidget* parent) : | ||||
|  | @ -26,6 +35,10 @@ PlacefileSettingsWidget::PlacefileSettingsWidget(QWidget* parent) : | |||
|     ui(new Ui::PlacefileSettingsWidget) | ||||
| { | ||||
|    ui->setupUi(this); | ||||
| 
 | ||||
|    p->openUrlDialog_ = new OpenUrlDialog("Add Placefile", this); | ||||
| 
 | ||||
|    p->ConnectSignals(); | ||||
| } | ||||
| 
 | ||||
| PlacefileSettingsWidget::~PlacefileSettingsWidget() | ||||
|  | @ -33,6 +46,21 @@ PlacefileSettingsWidget::~PlacefileSettingsWidget() | |||
|    delete ui; | ||||
| } | ||||
| 
 | ||||
| void PlacefileSettingsWidgetImpl::ConnectSignals() | ||||
| { | ||||
|    QObject::connect(self_->ui->addButton, | ||||
|                     &QPushButton::clicked, | ||||
|                     self_, | ||||
|                     [this]() { openUrlDialog_->open(); }); | ||||
| 
 | ||||
|    QObject::connect( | ||||
|       openUrlDialog_, | ||||
|       &OpenUrlDialog::accepted, | ||||
|       self_, | ||||
|       [this]() | ||||
|       { logger_->info("Add URL: {}", openUrlDialog_->url().toStdString()); }); | ||||
| } | ||||
| 
 | ||||
| } // namespace ui
 | ||||
| } // namespace qt
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat