Work on dynamic web browser menu.
This commit is contained in:
parent
1f13618f40
commit
d981a767ae
10 changed files with 67 additions and 47 deletions
|
@ -77,13 +77,21 @@ QSettings::Status Settings::setupSettings() {
|
||||||
|
|
||||||
if (QFile(app_path_file).exists()) {
|
if (QFile(app_path_file).exists()) {
|
||||||
s_instance = new Settings(app_path, QSettings::IniFormat, qApp);
|
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.",
|
qDebug("Initializing settings in %s.",
|
||||||
qPrintable(QDir::toNativeSeparators(app_path)));
|
qPrintable(QDir::toNativeSeparators(app_path)));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
s_instance = new Settings(home_path_file, QSettings::IniFormat, qApp);
|
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.",
|
qDebug("Initializing settings in %s.",
|
||||||
qPrintable(QDir::toNativeSeparators(home_path_file)));
|
qPrintable(QDir::toNativeSeparators(home_path_file)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,11 +22,13 @@ FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain
|
||||||
|
|
||||||
// Prepare main window and tabs.
|
// Prepare main window and tabs.
|
||||||
prepareMenus();
|
prepareMenus();
|
||||||
m_ui->m_tabWidget->initializeTabs();
|
|
||||||
|
|
||||||
// Establish connections.
|
// Establish connections.
|
||||||
createConnections();
|
createConnections();
|
||||||
|
|
||||||
|
// Prepare tabs.
|
||||||
|
m_ui->m_tabWidget->initializeTabs();
|
||||||
|
|
||||||
setupIcons();
|
setupIcons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +167,19 @@ void FormMain::createConnections() {
|
||||||
|
|
||||||
// General connections.
|
// General connections.
|
||||||
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanupResources()));
|
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) {
|
void FormMain::closeEvent(QCloseEvent *event) {
|
||||||
|
|
|
@ -64,6 +64,8 @@ class FormMain : public QMainWindow {
|
||||||
// Used for last-minute cleanups.
|
// Used for last-minute cleanups.
|
||||||
void cleanupResources();
|
void cleanupResources();
|
||||||
|
|
||||||
|
void loadWebBrowserMenu(int index);
|
||||||
|
|
||||||
// Displays various dialogs.
|
// Displays various dialogs.
|
||||||
void showSettings();
|
void showSettings();
|
||||||
void showAbout();
|
void showAbout();
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>800</width>
|
<width>800</width>
|
||||||
<height>19</height>
|
<height>21</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="m_menuFile">
|
<widget class="QMenu" name="m_menuFile">
|
||||||
|
@ -66,8 +66,14 @@
|
||||||
</property>
|
</property>
|
||||||
<addaction name="m_actionSettings"/>
|
<addaction name="m_actionSettings"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QMenu" name="m_menuWebBrowser">
|
||||||
|
<property name="title">
|
||||||
|
<string>Web browser</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
<addaction name="m_menuFile"/>
|
<addaction name="m_menuFile"/>
|
||||||
<addaction name="m_menuView"/>
|
<addaction name="m_menuView"/>
|
||||||
|
<addaction name="m_menuWebBrowser"/>
|
||||||
<addaction name="m_menuTools"/>
|
<addaction name="m_menuTools"/>
|
||||||
<addaction name="m_menuHelp"/>
|
<addaction name="m_menuHelp"/>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -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->setColumnCount(5);
|
||||||
m_ui->m_treeLanguages->setHeaderHidden(false);
|
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
|
#if QT_VERSION >= 0x050000
|
||||||
// Setup languages.
|
// Setup languages.
|
||||||
m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
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);
|
m_ui->m_treeSkins->header()->setResizeMode(3, QHeaderView::ResizeToContents);
|
||||||
#endif
|
#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.
|
// Establish needed connections.
|
||||||
connect(m_ui->m_buttonBox, SIGNAL(accepted()),
|
connect(m_ui->m_buttonBox, SIGNAL(accepted()),
|
||||||
this, SLOT(saveSettings()));
|
this, SLOT(saveSettings()));
|
||||||
|
|
|
@ -189,11 +189,6 @@
|
||||||
<property name="expandsOnDoubleClick">
|
<property name="expandsOnDoubleClick">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string notr="true">1</string>
|
|
||||||
</property>
|
|
||||||
</column>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
|
|
|
@ -25,7 +25,7 @@ class TabContent : public QWidget {
|
||||||
// This can be used for obtaining the menu from the instance and so on.
|
// This can be used for obtaining the menu from the instance and so on.
|
||||||
virtual WebBrowser *webBrowser() = 0;
|
virtual WebBrowser *webBrowser() = 0;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
int m_index;
|
int m_index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -160,7 +160,7 @@ int TabWidget::addBrowser(bool move_after_current,
|
||||||
this, SLOT(changeIcon(int,QIcon)));
|
this, SLOT(changeIcon(int,QIcon)));
|
||||||
|
|
||||||
// Setup the tab index.
|
// Setup the tab index.
|
||||||
browser->setTabIndex(final_index);
|
browser->setIndex(final_index);
|
||||||
|
|
||||||
// Load initial web page if desired.
|
// Load initial web page if desired.
|
||||||
if (initial_url.isValid()) {
|
if (initial_url.isValid()) {
|
||||||
|
@ -195,6 +195,6 @@ void TabWidget::fixContentsAfterMove(int from, int to) {
|
||||||
void TabWidget::fixContentsIndexes(int starting_index, int ending_index) {
|
void TabWidget::fixContentsIndexes(int starting_index, int ending_index) {
|
||||||
for ( ; starting_index <= ending_index; starting_index++) {
|
for ( ; starting_index <= ending_index; starting_index++) {
|
||||||
TabContent *content = static_cast<TabContent*>(widget(starting_index));
|
TabContent *content = static_cast<TabContent*>(widget(starting_index));
|
||||||
content->webBrowser()->setTabIndex(starting_index);
|
content->webBrowser()->setIndex(starting_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,12 +25,13 @@ WebBrowser::WebBrowser(QWidget *parent)
|
||||||
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
m_toolBar(new QToolBar(tr("Navigation panel"), this)),
|
||||||
m_webView(new BaseWebView(this)),
|
m_webView(new BaseWebView(this)),
|
||||||
m_txtLocation(new LocationLineEdit(this)),
|
m_txtLocation(new LocationLineEdit(this)),
|
||||||
m_tabIndex(-1),
|
|
||||||
m_actionBack(m_webView->pageAction(QWebPage::Back)),
|
m_actionBack(m_webView->pageAction(QWebPage::Back)),
|
||||||
m_actionForward(m_webView->pageAction(QWebPage::Forward)),
|
m_actionForward(m_webView->pageAction(QWebPage::Forward)),
|
||||||
m_actionReload(m_webView->pageAction(QWebPage::Reload)),
|
m_actionReload(m_webView->pageAction(QWebPage::Reload)),
|
||||||
m_actionStop(m_webView->pageAction(QWebPage::Stop)) {
|
m_actionStop(m_webView->pageAction(QWebPage::Stop)) {
|
||||||
|
|
||||||
|
m_index = -1;
|
||||||
|
|
||||||
// Add this new instance to the global list of web browsers.
|
// Add this new instance to the global list of web browsers.
|
||||||
// NOTE: This is used primarily for dynamic icon theme switching.
|
// NOTE: This is used primarily for dynamic icon theme switching.
|
||||||
m_runningWebBrowsers.append(this);
|
m_runningWebBrowsers.append(this);
|
||||||
|
@ -94,33 +95,24 @@ void WebBrowser::createConnections() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::onIconChanged() {
|
void WebBrowser::onIconChanged() {
|
||||||
emit iconChanged(m_tabIndex, m_webView->icon());
|
emit iconChanged(m_index, m_webView->icon());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebBrowser::onTitleChanged(const QString &new_title) {
|
void WebBrowser::onTitleChanged(const QString &new_title) {
|
||||||
if (new_title.isEmpty()) {
|
if (new_title.isEmpty()) {
|
||||||
emit titleChanged(m_tabIndex, tr("No title"));
|
emit titleChanged(m_index, tr("No title"));
|
||||||
}
|
}
|
||||||
else {
|
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) {
|
void WebBrowser::updateUrl(const QUrl &url) {
|
||||||
m_txtLocation->setText(url.toString());
|
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) {
|
void WebBrowser::navigateToUrl(const QUrl &url) {
|
||||||
if (url.isValid()) {
|
if (url.isValid()) {
|
||||||
m_webView->load(url);
|
m_webView->load(url);
|
||||||
|
@ -149,8 +141,12 @@ WebBrowser *WebBrowser::webBrowser() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMenu *WebBrowser::globalMenu() {
|
QList<QAction *> WebBrowser::globalMenu() {
|
||||||
return NULL;
|
QList<QAction*> browser_menu;
|
||||||
|
|
||||||
|
browser_menu.append(m_actionReload);
|
||||||
|
|
||||||
|
return browser_menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon WebBrowser::icon() {
|
QIcon WebBrowser::icon() {
|
||||||
|
|
|
@ -38,7 +38,7 @@ class WebBrowser : public TabContent {
|
||||||
WebBrowser *webBrowser();
|
WebBrowser *webBrowser();
|
||||||
|
|
||||||
// Returns global menu for this web browser.
|
// Returns global menu for this web browser.
|
||||||
QMenu *globalMenu();
|
QList<QAction*> globalMenu();
|
||||||
|
|
||||||
// Returns pointer to global network access manager
|
// Returns pointer to global network access manager
|
||||||
// for web browsers.
|
// for web browsers.
|
||||||
|
@ -49,10 +49,6 @@ class WebBrowser : public TabContent {
|
||||||
// Returns list of all running web browsers.
|
// Returns list of all running web browsers.
|
||||||
static QList<WebBrowser*> runningWebBrowsers();
|
static QList<WebBrowser*> runningWebBrowsers();
|
||||||
|
|
||||||
// Tab index getter/setter.
|
|
||||||
int tabIndex() const;
|
|
||||||
void setTabIndex(int tab_index);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
// Switches visibility of navigation bar.
|
// Switches visibility of navigation bar.
|
||||||
void setNavigationBarVisible(bool visible);
|
void setNavigationBarVisible(bool visible);
|
||||||
|
@ -84,7 +80,6 @@ class WebBrowser : public TabContent {
|
||||||
QToolBar *m_toolBar;
|
QToolBar *m_toolBar;
|
||||||
BaseWebView *m_webView;
|
BaseWebView *m_webView;
|
||||||
LocationLineEdit *m_txtLocation;
|
LocationLineEdit *m_txtLocation;
|
||||||
int m_tabIndex;
|
|
||||||
|
|
||||||
QAction *m_actionBack;
|
QAction *m_actionBack;
|
||||||
QAction *m_actionForward;
|
QAction *m_actionForward;
|
||||||
|
|
Loading…
Add table
Reference in a new issue