Skip to content

Instantly share code, notes, and snippets.

@Katarn
Created February 1, 2014 14:56
Show Gist options
  • Save Katarn/8753344 to your computer and use it in GitHub Desktop.
Save Katarn/8753344 to your computer and use it in GitHub Desktop.
diff --git a/resources/schemas/options.ini b/resources/schemas/options.ini
index 3bf8faa..1e3d070 100644
--- a/resources/schemas/options.ini
+++ b/resources/schemas/options.ini
@@ -78,6 +78,10 @@ value=false
type=bool
value=true
+[Browser/SearchWidgetWidth]
+type=integer
+value=320
+
[Browser/ShowSelectionContextMenuOnDoubleClick]
type=bool
value=true
diff --git a/src/ui/Window.cpp b/src/ui/Window.cpp
index 09952b5..e74d792 100644
--- a/src/ui/Window.cpp
+++ b/src/ui/Window.cpp
@@ -302,6 +302,11 @@ void Window::setPinned(bool pinned)
}
}
+void Window::onSplitterMoved(int pos, int index)
+{
+ SettingsManager::setValue(QStringLiteral("Browser/SearchWidgetWidth"), m_ui->splitter->sizes().at(1));
+}
+
void Window::setContentsWidget(ContentsWidget *widget)
{
if (m_contentsWidget)
@@ -340,6 +345,9 @@ void Window::setContentsWidget(ContentsWidget *widget)
m_ui->forwardButton->setMenu(NULL);
}
+ m_ui->splitter->setStretchFactor(0, 1);
+ m_ui->splitter->setStretchFactor(1, 0);
+
layout()->addWidget(m_contentsWidget);
m_ui->navigationWidget->setVisible(m_contentsWidget->getType() == QLatin1String("web"));
@@ -370,6 +378,11 @@ void Window::setContentsWidget(ContentsWidget *widget)
emit titleChanged(m_contentsWidget->getTitle());
emit iconChanged(m_contentsWidget->getIcon());
+ optionChanged(QLatin1String("Browser/SearchWidgetWidth"), SettingsManager::getValue(QLatin1String("Browser/SearchWidgetWidth")));
+
+ connect(SettingsManager::getInstance(), SIGNAL(valueChanged(QString,QVariant)), this, SLOT(optionChanged(QString,QVariant)));
+ connect(m_ui->splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(onSplitterMoved(int,int)));
+
connect(this, SIGNAL(aboutToClose()), m_contentsWidget, SLOT(close()));
connect(m_contentsWidget, SIGNAL(requestedAddBookmark(QUrl,QString)), this, SIGNAL(requestedAddBookmark(QUrl,QString)));
connect(m_contentsWidget, SIGNAL(requestedOpenUrl(QUrl,bool,bool,bool)), this, SIGNAL(requestedOpenUrl(QUrl,bool,bool,bool)));
@@ -386,6 +399,25 @@ void Window::setContentsWidget(ContentsWidget *widget)
connect(m_contentsWidget, SIGNAL(zoomChanged(int)), this, SIGNAL(zoomChanged(int)));
}
+void Window::optionChanged(const QString &option, const QVariant &value)
+{
+ if (option == QLatin1String("Browser/SearchWidgetWidth"))
+ {
+ QList<int> sizes;
+
+ int addressWidth;
+ int searchWidth;
+
+ searchWidth = value.toInt();
+ addressWidth = m_ui->splitter->width() - searchWidth;
+
+ sizes << addressWidth;
+ sizes << searchWidth;
+
+ m_ui->splitter->setSizes(sizes);
+ }
+}
+
Window* Window::clone(QWidget *parent)
{
if (!m_contentsWidget || !canClone())
diff --git a/src/ui/Window.h b/src/ui/Window.h
index 3965d0e..7fea1f8 100644
--- a/src/ui/Window.h
+++ b/src/ui/Window.h
@@ -164,12 +164,14 @@ protected:
void setContentsWidget(ContentsWidget *widget);
protected slots:
+ void optionChanged(const QString &option, const QVariant &value);
void goToHistoryIndex(QAction *action);
void notifyLoadingStateChanged(bool loading);
void notifyRequestedCloseWindow();
void notifyRequestedOpenUrl(const QUrl &url, bool background, bool newWindow);
void updateGoBackMenu();
void updateGoForwardMenu();
+ void onSplitterMoved(int pos, int index);
private:
ContentsWidget *m_contentsWidget;
@@ -194,6 +196,7 @@ signals:
void loadingStateChanged(WindowLoadingState loading);
void zoomChanged(int zoom);
void isPinnedChanged(bool pinned);
+ void splitterMoved(int pos, int index);
};
}
diff --git a/src/ui/Window.ui b/src/ui/Window.ui
index 3a99779..ea13721 100644
--- a/src/ui/Window.ui
+++ b/src/ui/Window.ui
@@ -6,40 +6,34 @@
<rect>
<x>0</x>
<y>0</y>
- <width>348</width>
+ <width>340</width>
<height>27</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
- <property name="leftMargin">
+ <property name="spacing">
<number>0</number>
</property>
- <property name="topMargin">
- <number>0</number>
- </property>
- <property name="rightMargin">
- <number>0</number>
- </property>
- <property name="bottomMargin">
+ <property name="margin">
<number>0</number>
</property>
<item>
<widget class="QWidget" name="navigationWidget" native="true">
- <layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,3,1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
- <number>5</number>
+ <number>-1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
- <number>0</number>
+ <number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
- <number>0</number>
+ <number>4</number>
</property>
<item>
<widget class="QToolButton" name="backButton">
@@ -63,15 +57,30 @@
</widget>
</item>
<item>
- <widget class="Otter::AddressWidget" name="addressWidget">
- <property name="placeholderText">
- <string>Enter Address...</string>
+ <widget class="QSplitter" name="splitter">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
</property>
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="opaqueResize">
+ <bool>true</bool>
+ </property>
+ <property name="childrenCollapsible">
+ <bool>false</bool>
+ </property>
+ <widget class="Otter::AddressWidget" name="addressWidget">
+ <property name="placeholderText">
+ <string>Enter Address...</string>
+ </property>
+ </widget>
+ <widget class="Otter::SearchWidget" name="searchWidget"/>
</widget>
</item>
- <item>
- <widget class="Otter::SearchWidget" name="searchWidget"/>
- </item>
</layout>
</widget>
</item>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment