diff --git a/qt/i2pd_qt/TunnelPane.cpp b/qt/i2pd_qt/TunnelPane.cpp index bbf5914d..fb840276 100644 --- a/qt/i2pd_qt/TunnelPane.cpp +++ b/qt/i2pd_qt/TunnelPane.cpp @@ -186,7 +186,8 @@ void TunnelPane::appendControlsForI2CPParameters(I2CPParameters& i2cpParameters, void TunnelPane::updated() { std::string oldName=tunnelConfig->getName(); //validate and show red if invalid - if(!applyDataFromUIToTunnelConfig())return; + hideWrongInputLabel(); + if(!mainWindow->applyTunnelsUiToConfigs())return; tunnelsPageUpdateListener->updated(oldName, tunnelConfig); } @@ -199,6 +200,7 @@ void TunnelPane::deleteButtonReleased() { switch (ret) { case QMessageBox::Ok: // OK was clicked + hideWrongInputLabel(); tunnelsPageUpdateListener->needsDeleting(tunnelConfig->getName()); break; case QMessageBox::Cancel: @@ -233,9 +235,15 @@ void TunnelPane::deleteTunnelForm() { void TunnelPane::highlightWrongInput(QString warningText, QWidget* controlWithWrongInput) { wrongInputPane->setVisible(true); wrongInputLabel->setText(warningText); + mainWindow->adjustSizesAccordingToWrongLabel(); if(controlWithWrongInput){ mainWindow->ui->tunnelsScrollArea->ensureWidgetVisible(controlWithWrongInput); controlWithWrongInput->setFocus(); } mainWindow->showTunnelsPage(); } + +void TunnelPane::hideWrongInputLabel() const { + wrongInputPane->setVisible(false); + mainWindow->adjustSizesAccordingToWrongLabel(); +} diff --git a/qt/i2pd_qt/TunnelPane.h b/qt/i2pd_qt/TunnelPane.h index 3a647635..a7012810 100644 --- a/qt/i2pd_qt/TunnelPane.h +++ b/qt/i2pd_qt/TunnelPane.h @@ -35,7 +35,7 @@ public: void deleteTunnelForm(); - void hideWrongInputLabel() const { wrongInputPane->setVisible(false); } + void hideWrongInputLabel() const; void highlightWrongInput(QString warningText, QWidget* controlWithWrongInput); virtual ServerTunnelPane* asServerTunnelPane()=0; @@ -95,7 +95,6 @@ protected: public: //returns false when invalid data at UI virtual bool applyDataFromUIToTunnelConfig() { - hideWrongInputLabel(); tunnelConfig->setName(nameLineEdit->text().toStdString()); tunnelConfig->setType(readTunnelTypeComboboxData()); I2CPParameters& i2cpParams=tunnelConfig->getI2cpParameters(); diff --git a/qt/i2pd_qt/mainwindow.cpp b/qt/i2pd_qt/mainwindow.cpp index aba00cec..93da099a 100644 --- a/qt/i2pd_qt/mainwindow.cpp +++ b/qt/i2pd_qt/mainwindow.cpp @@ -75,6 +75,7 @@ MainWindow::MainWindow(QWidget *parent) : int w = 683; int h = 3060; ui->settingsContents->setFixedSize(w, h); + ui->settingsContents->setGeometry(QRect(0,0,w,h)); /* QPalette pal(palette()); @@ -86,8 +87,10 @@ MainWindow::MainWindow(QWidget *parent) : pal.setColor(QPalette::Background, Qt::red); ui->wrongInputLabel->setAutoFillBackground(true); ui->wrongInputLabel->setPalette(pal); + ui->wrongInputLabel->setMaximumHeight(ui->wrongInputLabel->sizeHint().height()); ui->wrongInputLabel->setVisible(false); + settingsTitleLabelNominalHeight = ui->settingsTitleLabel->height(); #ifndef ANDROID createActions(); createTrayIcon(); @@ -629,8 +632,6 @@ void MainWindow::loadAllConfigs(){ /** returns false iff not valid items present and save was aborted */ bool MainWindow::saveAllConfigs(){ QString cannotSaveSettings = QApplication::tr("Cannot save settings."); - ui->wrongInputLabel->setVisible(false); - programOptionsWriterCurrentSection=""; /*if(!logFileNameOption->lineEdit->text().trimmed().isEmpty())logOption->optionValue=boost::any(std::string("file")); else logOption->optionValue=boost::any(std::string("stdout"));*/ @@ -679,15 +680,22 @@ void FolderChooserItem::pushButtonReleased() { } void BaseStringItem::installListeners(MainWindow *mainWindow) { - QObject::connect(lineEdit, SIGNAL(textChanged(const QString &)), mainWindow, SLOT(saveAllConfigs())); + QObject::connect(lineEdit, SIGNAL(textChanged(const QString &)), mainWindow, SLOT(updated())); } void ComboBoxItem::installListeners(MainWindow *mainWindow) { - QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), mainWindow, SLOT(saveAllConfigs())); + QObject::connect(comboBox, SIGNAL(currentIndexChanged(int)), mainWindow, SLOT(updated())); } void CheckBoxItem::installListeners(MainWindow *mainWindow) { - QObject::connect(checkBox, SIGNAL(stateChanged(int)), mainWindow, SLOT(saveAllConfigs())); + QObject::connect(checkBox, SIGNAL(stateChanged(int)), mainWindow, SLOT(updated())); } +void MainWindow::updated() { + ui->wrongInputLabel->setVisible(false); + adjustSizesAccordingToWrongLabel(); + + applyTunnelsUiToConfigs(); + saveAllConfigs(); +} void MainWindowItem::installListeners(MainWindow *mainWindow) {} @@ -751,6 +759,14 @@ void MainWindow::deleteTunnelForms() { tunnelPanes.clear(); } +bool MainWindow::applyTunnelsUiToConfigs() { + for(std::list::iterator it = tunnelPanes.begin(); it != tunnelPanes.end(); ++it) { + TunnelPane* tp = *it; + if(!tp->applyDataFromUIToTunnelConfig())return false; + } + return true; +} + void MainWindow::reloadTunnelsConfigAndUI(std::string tunnelNameToFocus) { deleteTunnelForms(); for (std::map::iterator it=tunnelConfigs.begin(); it!=tunnelConfigs.end(); ++it) { @@ -851,9 +867,40 @@ void MainWindow::backClickedFromChild() { showStatusPage(statusPage); } +void MainWindow::adjustSizesAccordingToWrongLabel() { + if(ui->wrongInputLabel->isVisible()) { + int dh = ui->wrongInputLabel->height()+ui->verticalLayout_7->layout()->spacing(); + ui->verticalLayout_7->invalidate(); + ui->wrongInputLabel->adjustSize(); + ui->stackedWidget->adjustSize(); + ui->stackedWidget->setFixedHeight(531-dh); + ui->settingsPage->setFixedHeight(531-dh); + ui->verticalLayoutWidget_4->setGeometry(QRect(0, 0, 711, 531-dh)); + ui->stackedWidget->setFixedHeight(531-dh); + ui->settingsScrollArea->setFixedHeight(531-dh-settingsTitleLabelNominalHeight-ui->verticalLayout_4->spacing()); + ui->settingsTitleLabel->setFixedHeight(settingsTitleLabelNominalHeight); + ui->tunnelsScrollArea->setFixedHeight(531-dh-settingsTitleLabelNominalHeight-ui->horizontalLayout_42->geometry().height()-2*ui->verticalLayout_4->spacing()); + ui->tunnelsTitleLabel->setFixedHeight(settingsTitleLabelNominalHeight); + }else{ + ui->verticalLayout_7->invalidate(); + ui->wrongInputLabel->adjustSize(); + ui->stackedWidget->adjustSize(); + ui->stackedWidget->setFixedHeight(531); + ui->settingsPage->setFixedHeight(531); + ui->verticalLayoutWidget_4->setGeometry(QRect(0, 0, 711, 531)); + ui->stackedWidget->setFixedHeight(531); + ui->settingsScrollArea->setFixedHeight(531-settingsTitleLabelNominalHeight-ui->verticalLayout_4->spacing()); + ui->settingsTitleLabel->setFixedHeight(settingsTitleLabelNominalHeight); + ui->tunnelsScrollArea->setFixedHeight(531-settingsTitleLabelNominalHeight-ui->horizontalLayout_42->geometry().height()-2*ui->verticalLayout_4->spacing()); + ui->tunnelsTitleLabel->setFixedHeight(settingsTitleLabelNominalHeight); + } +} + void MainWindow::highlightWrongInput(QString warningText, QWidget* widgetToFocus) { + bool redVisible = ui->wrongInputLabel->isVisible(); ui->wrongInputLabel->setVisible(true); ui->wrongInputLabel->setText(warningText); + if(!redVisible)adjustSizesAccordingToWrongLabel(); if(widgetToFocus){ui->settingsScrollArea->ensureWidgetVisible(widgetToFocus);widgetToFocus->setFocus();} showSettingsPage(); } diff --git a/qt/i2pd_qt/mainwindow.h b/qt/i2pd_qt/mainwindow.h index df8ab1e8..7e55a65f 100644 --- a/qt/i2pd_qt/mainwindow.h +++ b/qt/i2pd_qt/mainwindow.h @@ -387,10 +387,10 @@ public: //#endif private: - enum StatusPage {main_page, commands, local_destinations, leasesets, tunnels, transit_tunnels, transports, i2p_tunnels, sam_sessions}; private slots: + void updated(); void handleQuitButton(); void handleGracefulQuitButton(); @@ -446,7 +446,10 @@ public: Ui::StatusButtonsForm* statusButtonsUI; Ui::routerCommandsWidget* routerCommandsUI; Ui::GeneralSettingsContentsForm* uiSettings; + void adjustSizesAccordingToWrongLabel(); + bool applyTunnelsUiToConfigs(); private: + int settingsTitleLabelNominalHeight; TextBrowserTweaked1 * textBrowser; QWidget * routerCommandsParent; PageWithBackButton * pageWithBackButton; diff --git a/qt/i2pd_qt/mainwindow.ui b/qt/i2pd_qt/mainwindow.ui index b4aaed1d..9b463f44 100644 --- a/qt/i2pd_qt/mainwindow.ui +++ b/qt/i2pd_qt/mainwindow.ui @@ -169,6 +169,9 @@ + + QLayout::SetMinAndMaxSize + @@ -606,7 +609,7 @@ - + 0 0 @@ -624,11 +627,11 @@ - 0 + 2 - + 0 0 @@ -670,7 +673,7 @@ - + 0 0 @@ -686,7 +689,7 @@ - QLayout::SetMaximumSize + QLayout::SetMinAndMaxSize @@ -702,6 +705,12 @@ + + + 0 + 0 + + Qt::ScrollBarAlwaysOn @@ -750,7 +759,7 @@ QLayout::SetMinAndMaxSize - + 15 @@ -869,7 +878,7 @@ - + 0 0