Plug the search widget in the main window (top dock)
Move all dock-related initialization to a dedicated function
This commit is contained in:
		
					parent
					
						
							
								45016bd3a2
							
						
					
				
			
			
				commit
				
					
						bc63d4e575
					
				
			
		
					 2 changed files with 91 additions and 24 deletions
				
			
		| 
						 | 
					@ -44,6 +44,7 @@
 | 
				
			||||||
#include "model/danboorupoolmodel.h"
 | 
					#include "model/danboorupoolmodel.h"
 | 
				
			||||||
#include "mainwindow.h"
 | 
					#include "mainwindow.h"
 | 
				
			||||||
#include "danbooruconnectwidget.h"
 | 
					#include "danbooruconnectwidget.h"
 | 
				
			||||||
 | 
					#include "danboorusearchwidget.h"
 | 
				
			||||||
#include "danboorusettings.h"
 | 
					#include "danboorusettings.h"
 | 
				
			||||||
#include "generalpage.h"
 | 
					#include "generalpage.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -62,8 +63,10 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
      m_model(new DanbooruPostModel(this)),
 | 
					      m_model(new DanbooruPostModel(this)),
 | 
				
			||||||
      m_poolModel(new DanbooruPoolModel(this)),
 | 
					      m_poolModel(new DanbooruPoolModel(this)),
 | 
				
			||||||
      m_service(new DanbooruService()),
 | 
					      m_service(new DanbooruService()),
 | 
				
			||||||
 | 
					      m_connectWidget(nullptr),
 | 
				
			||||||
 | 
					      m_searchWidget(new DanbooruSearchWidget(this)),
 | 
				
			||||||
      m_tableView(new QTableView(this)),
 | 
					      m_tableView(new QTableView(this)),
 | 
				
			||||||
      m_cache(0)
 | 
					      m_cache(nullptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_service->setParent(this);
 | 
					    m_service->setParent(this);
 | 
				
			||||||
| 
						 | 
					@ -99,21 +102,11 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QVector<QUrl> boardsList = { QUrl("http://konachan.com"), QUrl("https://yande.re") };
 | 
					    QVector<QUrl> boardsList = { QUrl("http://konachan.com"), QUrl("https://yande.re") };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    m_connectWidget = new DanbooruConnectWidget(boardsList);
 | 
					    m_connectWidget = new DanbooruConnectWidget(boardsList, this);
 | 
				
			||||||
    statusBar()->addPermanentWidget(m_connectWidget);
 | 
					    statusBar()->addPermanentWidget(m_connectWidget);
 | 
				
			||||||
    m_connectWidget->hide();
 | 
					    m_connectWidget->hide();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Set up PoolWidget
 | 
					    setupDockWidgets();
 | 
				
			||||||
    m_tableView->setModel(m_poolModel);
 | 
					 | 
				
			||||||
    QDockWidget* dockWidget = new QDockWidget(i18n("Pools"), this);
 | 
					 | 
				
			||||||
    dockWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
 | 
					 | 
				
			||||||
    dockWidget->setWidget(m_tableView);
 | 
					 | 
				
			||||||
    dockWidget->setObjectName("PoolView");
 | 
					 | 
				
			||||||
    // Prevent the use of winId() when detached, leads to QQuickWidget bugs
 | 
					 | 
				
			||||||
    dockWidget->setFeatures(QDockWidget::DockWidgetClosable);
 | 
					 | 
				
			||||||
    addDockWidget(Qt::BottomDockWidgetArea, dockWidget);
 | 
					 | 
				
			||||||
    m_tableView->hide();
 | 
					 | 
				
			||||||
    dockWidget->hide();
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // then, setup our actions
 | 
					    // then, setup our actions
 | 
				
			||||||
    setupActions();
 | 
					    setupActions();
 | 
				
			||||||
| 
						 | 
					@ -139,10 +132,12 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
        actionCollection()->action(QLatin1String("find"))->setEnabled(true);
 | 
					        actionCollection()->action(QLatin1String("find"))->setEnabled(true);
 | 
				
			||||||
        actionCollection()->action(QLatin1String("poolDownload"))->setEnabled(true);
 | 
					        actionCollection()->action(QLatin1String("poolDownload"))->setEnabled(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        m_view->rootObject()->setProperty("poolMode", QVariant(false));
 | 
					        if (DanbooruSettings::self()->autoDownload()) {
 | 
				
			||||||
        m_connectWidget->hide();
 | 
					            m_view->rootObject()->setProperty("poolMode", QVariant(false));
 | 
				
			||||||
        m_service->setPostTags(QStringList());
 | 
					            m_connectWidget->hide();
 | 
				
			||||||
        m_service->getPostList();
 | 
					            m_service->setPostTags(QStringList());
 | 
				
			||||||
 | 
					            m_service->getPostList();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,9 +162,20 @@ DanbooruMainWindow::DanbooruMainWindow(QWidget *parent)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connect(dockWidget, &QDockWidget::visibilityChanged, [this](bool visible) {
 | 
					    connect(m_searchWidget, &DanbooruSearchWidget::accepted, [this]() {
 | 
				
			||||||
        actionCollection()->action(QLatin1String("poolDownload"))->setChecked(visible);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					       QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
 | 
				
			||||||
 | 
					       searchDockWidget->hide();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					       m_model->clear();
 | 
				
			||||||
 | 
					       m_service->setPostTags(m_searchWidget->selectedTags());
 | 
				
			||||||
 | 
					       m_view->rootObject()->setProperty("poolMode", QVariant(false));
 | 
				
			||||||
 | 
					       m_service->getPostList();
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    connect(m_searchWidget, &DanbooruSearchWidget::rejected, [this]() {
 | 
				
			||||||
 | 
					        QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
 | 
				
			||||||
 | 
					        searchDockWidget->hide();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -189,6 +195,7 @@ void DanbooruMainWindow::loadSettings()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruMainWindow::setupActions()
 | 
					void DanbooruMainWindow::setupActions()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -199,7 +206,7 @@ void DanbooruMainWindow::setupActions()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
 | 
					    QAction *fetchAction = new QAction(QIcon::fromTheme(QLatin1String("download")),
 | 
				
			||||||
                                       i18n("Download"), this);
 | 
					                                       i18n("Download"), this);
 | 
				
			||||||
    QAction *findAction = new QAction(QIcon::fromTheme(QLatin1String("edit-find")),
 | 
					    KToggleAction *findAction = new KToggleAction(QIcon::fromTheme(QLatin1String("edit-find")),
 | 
				
			||||||
                                      i18n("Search"), this);
 | 
					                                      i18n("Search"), this);
 | 
				
			||||||
    KToggleAction *poolAction = new KToggleAction(QIcon::fromTheme(QLatin1String("image-x-generic")),
 | 
					    KToggleAction *poolAction = new KToggleAction(QIcon::fromTheme(QLatin1String("image-x-generic")),
 | 
				
			||||||
                                                  i18n("Pools"), this);
 | 
					                                                  i18n("Pools"), this);
 | 
				
			||||||
| 
						 | 
					@ -208,6 +215,9 @@ void DanbooruMainWindow::setupActions()
 | 
				
			||||||
    findAction->setEnabled(false);
 | 
					    findAction->setEnabled(false);
 | 
				
			||||||
    poolAction->setEnabled(false);
 | 
					    poolAction->setEnabled(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    poolAction->setChecked(false);
 | 
				
			||||||
 | 
					    findAction->setChecked(false);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    actionCollection()->addAction(QLatin1String("connect"), connectAction);
 | 
					    actionCollection()->addAction(QLatin1String("connect"), connectAction);
 | 
				
			||||||
    actionCollection()->addAction(QLatin1String("fetch"), fetchAction);
 | 
					    actionCollection()->addAction(QLatin1String("fetch"), fetchAction);
 | 
				
			||||||
    actionCollection()->addAction(QLatin1String("find"), findAction);
 | 
					    actionCollection()->addAction(QLatin1String("find"), findAction);
 | 
				
			||||||
| 
						 | 
					@ -215,19 +225,19 @@ void DanbooruMainWindow::setupActions()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    actionCollection()->setDefaultShortcut(connectAction, KStandardShortcut::Open);
 | 
					    actionCollection()->setDefaultShortcut(connectAction, KStandardShortcut::Open);
 | 
				
			||||||
    actionCollection()->setDefaultShortcut(findAction, KStandardShortcut::Find);
 | 
					    actionCollection()->setDefaultShortcut(findAction, KStandardShortcut::Find);
 | 
				
			||||||
    // actionCollection()->removeAction(actionCollection()->action("help_contents"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
 | 
					    KStandardAction::quit(qApp, SLOT(quit()), actionCollection());
 | 
				
			||||||
    KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
 | 
					    KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connect(connectAction, &QAction::triggered, this, &DanbooruMainWindow::connectToBoard);
 | 
					    connect(connectAction, &QAction::triggered, this, &DanbooruMainWindow::connectToBoard);
 | 
				
			||||||
    connect(fetchAction, &QAction::triggered, this, &DanbooruMainWindow::downloadPosts);
 | 
					    connect(fetchAction, &QAction::triggered, this, &DanbooruMainWindow::downloadPosts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    connect(poolAction, &KToggleAction::toggled, [this](bool checked) {
 | 
					    connect(poolAction, &KToggleAction::toggled, [this](bool checked) {
 | 
				
			||||||
        if (!m_service) {
 | 
					        if (!m_service) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        QDockWidget* dockWidget = findChild<QDockWidget*>(QLatin1String("PoolView"));
 | 
					        QDockWidget* poolDockWidget = findChild<QDockWidget*>(QLatin1String("PoolView"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (checked) {
 | 
					        if (checked) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -235,16 +245,69 @@ void DanbooruMainWindow::setupActions()
 | 
				
			||||||
                m_service->getPoolList();
 | 
					                m_service->getPoolList();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            dockWidget->show();
 | 
					            poolDockWidget->show();
 | 
				
			||||||
            m_tableView->show();
 | 
					            m_tableView->show();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            dockWidget->hide();
 | 
					            poolDockWidget->hide();
 | 
				
			||||||
            m_tableView->hide();
 | 
					            m_tableView->hide();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    connect(findAction, &KToggleAction::toggled, [this](bool checked) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        QDockWidget* searchDockWidget = findChild<QDockWidget*>(QLatin1String("SearchView"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (checked) {
 | 
				
			||||||
 | 
					            searchDockWidget->show();
 | 
				
			||||||
 | 
					            m_searchWidget->show();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            searchDockWidget->hide();
 | 
				
			||||||
 | 
					            m_searchWidget->hide();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void DanbooruMainWindow::setupDockWidgets() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Set up PoolWidget
 | 
				
			||||||
 | 
					    m_tableView->setModel(m_poolModel);
 | 
				
			||||||
 | 
					    QDockWidget* poolDockWidget = new QDockWidget(i18n("Pools"), this);
 | 
				
			||||||
 | 
					    poolDockWidget->setAllowedAreas(Qt::BottomDockWidgetArea);
 | 
				
			||||||
 | 
					    poolDockWidget->setWidget(m_tableView);
 | 
				
			||||||
 | 
					    poolDockWidget->setObjectName("PoolView");
 | 
				
			||||||
 | 
					    // Prevent the use of winId() when detached, leads to QQuickWidget bugs
 | 
				
			||||||
 | 
					    poolDockWidget->setFeatures(QDockWidget::DockWidgetClosable);
 | 
				
			||||||
 | 
					    addDockWidget(Qt::BottomDockWidgetArea, poolDockWidget);
 | 
				
			||||||
 | 
					    m_tableView->hide();
 | 
				
			||||||
 | 
					    poolDockWidget->hide();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Find widget
 | 
				
			||||||
 | 
					    QDockWidget *searchDockWidget = new QDockWidget(QLatin1String(""), this);
 | 
				
			||||||
 | 
					    searchDockWidget->setAllowedAreas(Qt::TopDockWidgetArea);
 | 
				
			||||||
 | 
					    searchDockWidget->setWidget(m_searchWidget);
 | 
				
			||||||
 | 
					    searchDockWidget->setObjectName("SearchView");
 | 
				
			||||||
 | 
					    // FIXME: Get rid of the close button in the widget
 | 
				
			||||||
 | 
					    searchDockWidget->setFeatures(QDockWidget::NoDockWidgetFeatures);
 | 
				
			||||||
 | 
					    addDockWidget(Qt::TopDockWidgetArea, searchDockWidget);
 | 
				
			||||||
 | 
					    searchDockWidget->hide();
 | 
				
			||||||
 | 
					    m_searchWidget->hide();
 | 
				
			||||||
 | 
					    searchDockWidget->setTitleBarWidget(new QWidget(this));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Connections
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    connect(poolDockWidget, &QDockWidget::visibilityChanged, [this](bool visible) {
 | 
				
			||||||
 | 
					        actionCollection()->action(QLatin1String("poolDownload"))->setChecked(visible);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    connect(searchDockWidget, &QDockWidget::visibilityChanged, [this](bool visible) {
 | 
				
			||||||
 | 
					        actionCollection()->action(QLatin1String("find"))->setChecked(visible);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void DanbooruMainWindow::connectToBoard()
 | 
					void DanbooruMainWindow::connectToBoard()
 | 
				
			||||||
| 
						 | 
					@ -267,6 +330,7 @@ void DanbooruMainWindow::downloadPosts()
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_model->clear();
 | 
				
			||||||
    m_service->setPostTags(QStringList());
 | 
					    m_service->setPostTags(QStringList());
 | 
				
			||||||
    m_view->rootObject()->setProperty("poolMode", QVariant(false));
 | 
					    m_view->rootObject()->setProperty("poolMode", QVariant(false));
 | 
				
			||||||
    m_service->getPostList();
 | 
					    m_service->getPostList();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -43,6 +43,7 @@ class DanbooruService;
 | 
				
			||||||
class DanbooruPostModel;
 | 
					class DanbooruPostModel;
 | 
				
			||||||
class DanbooruPoolModel;
 | 
					class DanbooruPoolModel;
 | 
				
			||||||
class DanbooruConnectWidget;
 | 
					class DanbooruConnectWidget;
 | 
				
			||||||
 | 
					class DanbooruSearchWidget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * This class serves as the main window for danbooru_client.  It handles the
 | 
					 * This class serves as the main window for danbooru_client.  It handles the
 | 
				
			||||||
| 
						 | 
					@ -62,6 +63,7 @@ private:
 | 
				
			||||||
    DanbooruPoolModel *m_poolModel;
 | 
					    DanbooruPoolModel *m_poolModel;
 | 
				
			||||||
    DanbooruService *m_service;
 | 
					    DanbooruService *m_service;
 | 
				
			||||||
    DanbooruConnectWidget *m_connectWidget;
 | 
					    DanbooruConnectWidget *m_connectWidget;
 | 
				
			||||||
 | 
					    DanbooruSearchWidget *m_searchWidget;
 | 
				
			||||||
    QTableView *m_tableView;
 | 
					    QTableView *m_tableView;
 | 
				
			||||||
    KImageCache *m_cache;
 | 
					    KImageCache *m_cache;
 | 
				
			||||||
    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
					    static QHash<int, DanbooruPost::Rating> ratingMap;
 | 
				
			||||||
| 
						 | 
					@ -79,6 +81,7 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void setupActions();
 | 
					    void setupActions();
 | 
				
			||||||
 | 
					    void setupDockWidgets();
 | 
				
			||||||
    void setupConnections();
 | 
					    void setupConnections();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private Q_SLOTS:
 | 
					private Q_SLOTS:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue