Work on dynamic web browser menu.

This commit is contained in:
Martin Rotter 2013-09-25 20:21:32 +02:00
parent 1f13618f40
commit d981a767ae
10 changed files with 67 additions and 47 deletions

View File

@ -77,13 +77,21 @@ QSettings::Status Settings::setupSettings() {
if (QFile(app_path_file).exists()) {
s_instance = new Settings(app_path, QSettings::IniFormat, qApp);
QWebSettings::setIconDatabasePath(app_path + QDir::separator() + APP_CFG_WEB_PATH);
QString web_path = app_path + QDir::separator() + APP_CFG_WEB_PATH;
QDir(web_path).mkpath(web_path);
QWebSettings::setIconDatabasePath(web_path);
qDebug("Initializing settings in %s.",
qPrintable(QDir::toNativeSeparators(app_path)));
}
else {
s_instance = new Settings(home_path_file, QSettings::IniFormat, qApp);
QWebSettings::setIconDatabasePath(home_path + QDir::separator() + APP_CFG_WEB_PATH);
QString web_path = home_path + QDir::separator() + APP_CFG_WEB_PATH;
QDir(web_path).mkpath(web_path);
QWebSettings::setIconDatabasePath(web_path);
qDebug("Initializing settings in %s.",
qPrintable(QDir::toNativeSeparators(home_path_file)));
}

View File

@ -22,11 +22,13 @@ FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain
// Prepare main window and tabs.
prepareMenus();
m_ui->m_tabWidget->initializeTabs();
// Establish connections.
createConnections();
// Prepare tabs.
m_ui->m_tabWidget->initializeTabs();
setupIcons();
}
@ -165,6 +167,19 @@ void FormMain::createConnections() {
// General connections.
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanupResources()));
// Menu "Web browser" connections.
connect(m_ui->m_tabWidget, SIGNAL(currentChanged(int)),
this, SLOT(loadWebBrowserMenu(int)));
}
void FormMain::loadWebBrowserMenu(int index) {
WebBrowser *active_browser = m_ui->m_tabWidget->widget(index)->webBrowser();
m_ui->m_menuWebBrowser->clear();
if (active_browser != NULL) {
m_ui->m_menuWebBrowser->addActions(active_browser->globalMenu());
}
}
void FormMain::closeEvent(QCloseEvent *event) {

View File

@ -64,6 +64,8 @@ class FormMain : public QMainWindow {
// Used for last-minute cleanups.
void cleanupResources();
void loadWebBrowserMenu(int index);
// Displays various dialogs.
void showSettings();
void showAbout();

View File

@ -36,7 +36,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>19</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="m_menuFile">
@ -66,8 +66,14 @@
</property>
<addaction name="m_actionSettings"/>
</widget>
<widget class="QMenu" name="m_menuWebBrowser">
<property name="title">
<string>Web browser</string>
</property>
</widget>
<addaction name="m_menuFile"/>
<addaction name="m_menuView"/>
<addaction name="m_menuWebBrowser"/>
<addaction name="m_menuTools"/>
<addaction name="m_menuHelp"/>
</widget>

View File

@ -28,6 +28,22 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
m_ui->m_treeLanguages->setColumnCount(5);
m_ui->m_treeLanguages->setHeaderHidden(false);
m_ui->m_treeLanguages->setHeaderLabels(QStringList()
<< tr("Language")
<< tr("Code")
<< tr("Version")
<< tr("Author")
<< tr("Email"));
m_ui->m_treeSkins->setColumnCount(4);
m_ui->m_treeSkins->setHeaderHidden(false);
m_ui->m_treeSkins->setHeaderLabels(QStringList()
<< tr("Name")
<< tr("Version")
<< tr("Author")
<< tr("Email"));
#if QT_VERSION >= 0x050000
// Setup languages.
m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
@ -56,19 +72,6 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
m_ui->m_treeSkins->header()->setResizeMode(3, QHeaderView::ResizeToContents);
#endif
m_ui->m_treeLanguages->setHeaderLabels(QStringList()
<< tr("Language")
<< tr("Code")
<< tr("Version")
<< tr("Author")
<< tr("Email"));
m_ui->m_treeSkins->setHeaderLabels(QStringList()
<< tr("Name")
<< tr("Version")
<< tr("Author")
<< tr("Email"));
// Establish needed connections.
connect(m_ui->m_buttonBox, SIGNAL(accepted()),
this, SLOT(saveSettings()));

View File

@ -189,11 +189,6 @@
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
<item row="3" column="0">

View File

@ -25,7 +25,7 @@ class TabContent : public QWidget {
// This can be used for obtaining the menu from the instance and so on.
virtual WebBrowser *webBrowser() = 0;
private:
protected:
int m_index;
};

View File

@ -160,7 +160,7 @@ int TabWidget::addBrowser(bool move_after_current,
this, SLOT(changeIcon(int,QIcon)));
// Setup the tab index.
browser->setTabIndex(final_index);
browser->setIndex(final_index);
// Load initial web page if desired.
if (initial_url.isValid()) {
@ -195,6 +195,6 @@ void TabWidget::fixContentsAfterMove(int from, int to) {
void TabWidget::fixContentsIndexes(int starting_index, int ending_index) {
for ( ; starting_index <= ending_index; starting_index++) {
TabContent *content = static_cast<TabContent*>(widget(starting_index));
content->webBrowser()->setTabIndex(starting_index);
content->webBrowser()->setIndex(starting_index);
}
}

View File

@ -25,12 +25,13 @@ WebBrowser::WebBrowser(QWidget *parent)
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
m_webView(new BaseWebView(this)),
m_txtLocation(new LocationLineEdit(this)),
m_tabIndex(-1),
m_actionBack(m_webView->pageAction(QWebPage::Back)),
m_actionForward(m_webView->pageAction(QWebPage::Forward)),
m_actionReload(m_webView->pageAction(QWebPage::Reload)),
m_actionStop(m_webView->pageAction(QWebPage::Stop)) {
m_index = -1;
// Add this new instance to the global list of web browsers.
// NOTE: This is used primarily for dynamic icon theme switching.
m_runningWebBrowsers.append(this);
@ -94,33 +95,24 @@ void WebBrowser::createConnections() {
}
void WebBrowser::onIconChanged() {
emit iconChanged(m_tabIndex, m_webView->icon());
emit iconChanged(m_index, m_webView->icon());
}
void WebBrowser::onTitleChanged(const QString &new_title) {
if (new_title.isEmpty()) {
emit titleChanged(m_tabIndex, tr("No title"));
emit titleChanged(m_index, tr("No title"));
}
else {
emit titleChanged(m_tabIndex, new_title);
emit titleChanged(m_index, new_title);
}
emit iconChanged(m_tabIndex, QIcon());
emit iconChanged(m_index, QIcon());
}
void WebBrowser::updateUrl(const QUrl &url) {
m_txtLocation->setText(url.toString());
}
int WebBrowser::tabIndex() const {
return m_tabIndex;
}
void WebBrowser::setTabIndex(int tab_index) {
m_tabIndex = tab_index;
}
void WebBrowser::navigateToUrl(const QUrl &url) {
if (url.isValid()) {
m_webView->load(url);
@ -149,8 +141,12 @@ WebBrowser *WebBrowser::webBrowser() {
return this;
}
QMenu *WebBrowser::globalMenu() {
return NULL;
QList<QAction *> WebBrowser::globalMenu() {
QList<QAction*> browser_menu;
browser_menu.append(m_actionReload);
return browser_menu;
}
QIcon WebBrowser::icon() {

View File

@ -38,7 +38,7 @@ class WebBrowser : public TabContent {
WebBrowser *webBrowser();
// Returns global menu for this web browser.
QMenu *globalMenu();
QList<QAction*> globalMenu();
// Returns pointer to global network access manager
// for web browsers.
@ -49,10 +49,6 @@ class WebBrowser : public TabContent {
// Returns list of all running web browsers.
static QList<WebBrowser*> runningWebBrowsers();
// Tab index getter/setter.
int tabIndex() const;
void setTabIndex(int tab_index);
public slots:
// Switches visibility of navigation bar.
void setNavigationBarVisible(bool visible);
@ -84,7 +80,6 @@ class WebBrowser : public TabContent {
QToolBar *m_toolBar;
BaseWebView *m_webView;
LocationLineEdit *m_txtLocation;
int m_tabIndex;
QAction *m_actionBack;
QAction *m_actionForward;