diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-03-20 16:27:03 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-03-20 16:27:03 +0100 |
commit | 32693ab1efcd708f0eba06c33fb5b52a59fd377b (patch) | |
tree | afc64b7f89d7880825d89d860dc30e2c05393936 | |
parent | Dockable bookmarks dialog (diff) | |
download | smolbote-32693ab1efcd708f0eba06c33fb5b52a59fd377b.tar.xz |
Fixed opening bookmarks with multiple windows
-rw-r--r-- | smolbote.qbs | 6 | ||||
-rw-r--r-- | src/browser.cpp | 4 | ||||
-rw-r--r-- | src/browser.h | 6 | ||||
-rw-r--r-- | src/forms/bookmarksdialog.ui | 118 | ||||
-rw-r--r-- | src/forms/bookmarksform.ui | 104 | ||||
-rw-r--r-- | src/forms/bookmarkswidget.cpp (renamed from src/forms/bookmarksdialog.cpp) | 50 | ||||
-rw-r--r-- | src/forms/bookmarkswidget.h (renamed from src/forms/bookmarksdialog.h) | 12 |
7 files changed, 148 insertions, 152 deletions
diff --git a/smolbote.qbs b/smolbote.qbs index 21e0165..46af2d5 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -79,9 +79,9 @@ Project { Group { name: "bookmarks" files: [ - "src/forms/bookmarksdialog.cpp", - "src/forms/bookmarksdialog.h", - "src/forms/bookmarksdialog.ui", + "src/forms/bookmarksform.ui", + "src/forms/bookmarkswidget.cpp", + "src/forms/bookmarkswidget.h", "src/xbel.cpp", "src/xbel.h", ] diff --git a/src/browser.cpp b/src/browser.cpp index 2c7115d..f96a881 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -99,7 +99,7 @@ bool Browser::preLaunch(QStringList urls) } m_networkAccessManager = new QNetworkAccessManager(); - m_bookmarksManager = new BookmarksDialog; + m_bookmarksManager = new BookmarksWidget; m_downloadManager = new DownloadDialog; QtWebEngine::initialize(); @@ -122,7 +122,7 @@ QNetworkAccessManager *Browser::network() return m_networkAccessManager; } -BookmarksDialog *Browser::bookmarks() +BookmarksWidget *Browser::bookmarks() { return m_bookmarksManager; } diff --git a/src/browser.h b/src/browser.h index a6820c8..41a55f3 100644 --- a/src/browser.h +++ b/src/browser.h @@ -23,7 +23,7 @@ #include <QApplication> #include <QVector> -#include "forms/bookmarksdialog.h" +#include "forms/bookmarkswidget.h" #include "forms/downloaddialog.h" #include <QLocalServer> #include "settings.h" @@ -54,7 +54,7 @@ public: Settings *settings(); QNetworkAccessManager *network(); - BookmarksDialog *bookmarks(); + BookmarksWidget *bookmarks(); DownloadDialog *downloads(); void setConfigPath(const QString &path); @@ -72,7 +72,7 @@ private: QLocalServer *m_localServer; QVector<MainWindow*> m_windows; QNetworkAccessManager *m_networkAccessManager; - BookmarksDialog *m_bookmarksManager; + BookmarksWidget *m_bookmarksManager; DownloadDialog *m_downloadManager; }; diff --git a/src/forms/bookmarksdialog.ui b/src/forms/bookmarksdialog.ui deleted file mode 100644 index f528528..0000000 --- a/src/forms/bookmarksdialog.ui +++ /dev/null @@ -1,118 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>BookmarksDialog</class> - <widget class="QDialog" name="BookmarksDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>820</width> - <height>480</height> - </rect> - </property> - <property name="windowTitle"> - <string>Bookmarks</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout_2"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QTreeWidget" name="treeWidget"> - <property name="dragEnabled"> - <bool>true</bool> - </property> - <property name="dragDropMode"> - <enum>QAbstractItemView::InternalMove</enum> - </property> - <property name="defaultDropAction"> - <enum>Qt::MoveAction</enum> - </property> - <column> - <property name="text"> - <string notr="true">Title</string> - </property> - </column> - <column> - <property name="text"> - <string>href</string> - </property> - </column> - </widget> - </item> - <item> - <layout class="QVBoxLayout" name="verticalLayout"> - <item> - <layout class="QHBoxLayout" name="horizontalLayout_2"> - <item> - <widget class="QToolButton" name="addFolder_toolButton"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item> - <widget class="QToolButton" name="addBookmark_toolButton"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item> - <widget class="QToolButton" name="addSeparator_toolButton"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - <item> - <widget class="QToolButton" name="deleteItem_toolButton"> - <property name="text"> - <string>...</string> - </property> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="minimumSize"> - <size> - <width>250</width> - <height>0</height> - </size> - </property> - <property name="maximumSize"> - <size> - <width>250</width> - <height>16777215</height> - </size> - </property> - <property name="title"> - <string>Details</string> - </property> - <layout class="QFormLayout" name="formLayout"> - <item row="1" column="0"> - <widget class="QLabel" name="href_label"> - <property name="text"> - <string>href</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="href_lineEdit"/> - </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="title_lineEdit"/> - </item> - </layout> - </widget> - </item> - </layout> - </item> - </layout> - </item> - </layout> - </widget> - <resources/> - <connections/> -</ui> diff --git a/src/forms/bookmarksform.ui b/src/forms/bookmarksform.ui new file mode 100644 index 0000000..2df0c4b --- /dev/null +++ b/src/forms/bookmarksform.ui @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BookmarksDialog</class> + <widget class="QWidget" name="BookmarksDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>420</width> + <height>600</height> + </rect> + </property> + <property name="minimumSize"> + <size> + <width>420</width> + <height>600</height> + </size> + </property> + <property name="windowTitle"> + <string>Bookmarks</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_2"> + <item> + <widget class="QToolButton" name="addFolder_toolButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="addBookmark_toolButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="addSeparator_toolButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + <item> + <widget class="QToolButton" name="deleteItem_toolButton"> + <property name="text"> + <string>...</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QTreeWidget" name="treeWidget"> + <property name="dragEnabled"> + <bool>true</bool> + </property> + <property name="dragDropMode"> + <enum>QAbstractItemView::InternalMove</enum> + </property> + <property name="defaultDropAction"> + <enum>Qt::MoveAction</enum> + </property> + <column> + <property name="text"> + <string notr="true">Title</string> + </property> + </column> + <column> + <property name="text"> + <string>href</string> + </property> + </column> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="title"> + <string>Details</string> + </property> + <layout class="QFormLayout" name="formLayout"> + <item row="1" column="0"> + <widget class="QLabel" name="href_label"> + <property name="text"> + <string>href</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="href_lineEdit"/> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="title_lineEdit"/> + </item> + </layout> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/forms/bookmarksdialog.cpp b/src/forms/bookmarkswidget.cpp index becac56..8985fff 100644 --- a/src/forms/bookmarksdialog.cpp +++ b/src/forms/bookmarkswidget.cpp @@ -18,14 +18,13 @@ ** ******************************************************************************/ -#include "bookmarksdialog.h" -#include "ui_bookmarksdialog.h" +#include "bookmarkswidget.h" +#include "ui_bookmarksform.h" #include "browser.h" #include <QTreeWidget> -#include <QDockWidget> -BookmarksDialog::BookmarksDialog(QWidget *parent) : - QDialog(parent), +BookmarksWidget::BookmarksWidget(QWidget *parent) : + QWidget(parent), ui(new Ui::BookmarksDialog) { // make sure this dialog does not get deleted on close @@ -34,6 +33,11 @@ BookmarksDialog::BookmarksDialog(QWidget *parent) : ui->setupUi(this); ui->treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch); + window = nullptr; + dock = new QDockWidget(tr("Bookmarks"), 0); + dock->setWidget(this); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + QStyle *style = ui->treeWidget->style(); ui->addFolder_toolButton->setIcon(style->standardPixmap(QStyle::SP_DirIcon)); ui->addBookmark_toolButton->setIcon(style->standardPixmap(QStyle::SP_FileIcon)); @@ -60,7 +64,7 @@ BookmarksDialog::BookmarksDialog(QWidget *parent) : }); } -BookmarksDialog::~BookmarksDialog() +BookmarksWidget::~BookmarksWidget() { qDebug("Destroying BookmarksManager"); @@ -72,36 +76,40 @@ BookmarksDialog::~BookmarksDialog() delete ui; } -void BookmarksDialog::show() +void BookmarksWidget::show() { - // show() is called by a QAction in MainWindow - w = qobject_cast<MainWindow *>(sender()->parent()); + // show() gets called by a QAction in MainWindow + window = qobject_cast<MainWindow *>(sender()->parent()); + if(window) { + + // dockable widgets + dock->setParent(window); + window->addDockWidget(Qt::RightDockWidgetArea, dock); - // dockable widgets - QDockWidget *bookmarksDock = new QDockWidget(tr("Bookmarks"), w); - bookmarksDock->setWidget(this); - bookmarksDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - w->addDockWidget(Qt::RightDockWidgetArea, bookmarksDock); - bookmarksDock->setFloating(true); + } else { + qWarning("BookmarksWidget not called by MainWindow"); + } - QDialog::show(); + QWidget::show(); } -void BookmarksDialog::deleteCurrentItem() +void BookmarksWidget::deleteCurrentItem() { delete ui->treeWidget->currentItem(); } -void BookmarksDialog::openItem(QTreeWidgetItem *item, int column) +void BookmarksWidget::openItem(QTreeWidgetItem *item, int column) { Q_UNUSED(column) - if(w) { - w->addNewTab(QUrl::fromUserInput(item->text(1))); + if(window) { + window->addNewTab(QUrl::fromUserInput(item->text(1))); + } else { + qWarning("Trying to open a link without a MainWindow set"); } } -void BookmarksDialog::showItemDetails() +void BookmarksWidget::showItemDetails() { QTreeWidgetItem *item = ui->treeWidget->currentItem(); if(!item) { diff --git a/src/forms/bookmarksdialog.h b/src/forms/bookmarkswidget.h index 0fcab42..9164079 100644 --- a/src/forms/bookmarksdialog.h +++ b/src/forms/bookmarkswidget.h @@ -21,7 +21,8 @@ #ifndef BOOKMARKSDIALOG_H #define BOOKMARKSDIALOG_H -#include <QDialog> +#include <QWidget> +#include <QDockWidget> #include "xbel.h" #include "mainwindow.h" @@ -29,13 +30,13 @@ namespace Ui { class BookmarksDialog; } -class BookmarksDialog : public QDialog +class BookmarksWidget : public QWidget { Q_OBJECT public: - explicit BookmarksDialog(QWidget *parent = 0); - ~BookmarksDialog(); + explicit BookmarksWidget(QWidget *parent = 0); + ~BookmarksWidget(); signals: void openUrl(const QUrl &url); @@ -52,7 +53,8 @@ private slots: void showItemDetails(); private: - MainWindow *w; + MainWindow *window; + QDockWidget *dock; Ui::BookmarksDialog *ui; Xbel *xbel; }; |