Commit e5ff55a3 authored by Victor Yacovlev's avatar Victor Yacovlev

Improved help viewer for use in small size window (not it can be docked

into i/o console space)
parent 9b1f3e7e
......@@ -10,7 +10,7 @@ namespace DocBookViewer {
static const QString MainFontFamily =
"Droid Serif,PT Serif,Garamond,Times New Roman,serif";
static const QString MainFontSize = "14pt";
static const QString MainFontSize = "12pt";
static const QString CodeFontFamily =
"DejaVu Sans Mono,Liberation Mono,PT Sans Mono,Courier New,monospace";
......@@ -23,11 +23,14 @@ ContentView::ContentView(QWidget *parent)
setOpenLinks(false);
connect(this, SIGNAL(anchorClicked(QUrl)),
this, SLOT(handleInternalLink(QUrl)));
connect(verticalScrollBar(), SIGNAL(sliderMoved(int)),
this, SLOT(clearLastAnchorUrl()));
ignoreClearAnchorUrl_ = false;
}
QSize ContentView::minimumSizeHint() const
{
return QSize(500, 400);
return QSize(500, 230);
}
void ContentView::reset()
......@@ -48,6 +51,7 @@ void ContentView::renderData(ModelPtr data)
QString anchor = modelToLink(data);
QUrl anchorUrl("#" + anchor);
setSource(anchorUrl);
lastAnchorUrl_ = anchorUrl;
}
}
......@@ -1502,4 +1506,33 @@ QString ContentView::formatProgramSourceText(
return result;
}
void ContentView::resizeEvent(QResizeEvent *e)
{
ignoreClearAnchorUrl_ = true;
QTextBrowser::resizeEvent(e);;
if (lastAnchorUrl_.isValid()) {
setSource(lastAnchorUrl_);
}
}
void ContentView::wheelEvent(QWheelEvent *e)
{
QTextBrowser::wheelEvent(e);
if (e->buttons() == Qt::NoButton) {
clearLastAnchorUrl();
}
}
void ContentView::clearLastAnchorUrl()
{
if (!ignoreClearAnchorUrl_) {
lastAnchorUrl_.clear();
// qDebug() << "Claar last anchor url";
}
else {
// qDebug() << "Ignored clear last anchor url";
}
ignoreClearAnchorUrl_ = false;
}
}
......@@ -6,6 +6,8 @@
#include <QtGlobal>
#include <QTextBrowser>
#include <QSharedPointer>
#include <QResizeEvent>
#include <QWheelEvent>
namespace DocBookViewer {
......@@ -27,6 +29,9 @@ signals:
void itemRequest(ModelPtr model);
private:
void resizeEvent(QResizeEvent *e);
void wheelEvent(QWheelEvent *e);
QString wrapHTML(const QString & body) const;
QString render(ModelPtr data) const;
QString renderElement(ModelPtr data) const;
......@@ -123,8 +128,11 @@ private:
private /*fields*/:
ModelPtr loadedModel_;
QUrl lastAnchorUrl_;
bool ignoreClearAnchorUrl_;
private slots:
void clearLastAnchorUrl();
void handleInternalLink(const QUrl & url);
......
#include "docbookview.h"
#include "docbookview_impl.h"
#include <QResizeEvent>
namespace DocBookViewer {
DocBookView::DocBookView(QWidget *parent)
......@@ -39,6 +41,18 @@ void DocBookView::showEvent(QShowEvent * event)
QWidget::showEvent(event);
}
void DocBookView::resizeEvent(QResizeEvent * event)
{
if (event->size().width() < minimumWidth() ||
event->size().height() < minimumHeight()) {
event->ignore();
}
else {
event->accept();
pImpl_->setSize(event->size());
}
}
DocBookView::~DocBookView()
{
......
......@@ -56,6 +56,7 @@ protected:
void showEvent(QShowEvent *);
void closeEvent(QCloseEvent *);
void hideEvent(QHideEvent *);
void resizeEvent(QResizeEvent *);
private:
class DocBookViewImpl* pImpl_;
......
......@@ -18,14 +18,33 @@ DocBookViewImpl::DocBookViewImpl(DocBookView *pClass)
: QObject(pClass)
, pClass_(pClass)
, settings_(nullptr)
, compactModeFlag_(false)
{
pClass_->setLayout(new QHBoxLayout);
smallSizeContainer_ = new QWidget(pClass);
smallSizeContainer_->move(0, 0);
smallSizeContainer_->setLayout(new QHBoxLayout);
smallSizeContainer_->layout()->setContentsMargins(0, 24, 0, 0);
background_ = new QWidget(pClass);
background_->move(0, 0);
splitterRightWidget_ = new QStackedWidget(pClass);
filler_ = new QWidget(pClass_);
splitterRightWidget_->addWidget(filler_);
enoughtSizeContainer_ = new QWidget(pClass);
enoughtSizeContainer_->setLayout(new QHBoxLayout);
enoughtSizeContainer_->layout()->setContentsMargins(0, 0, 0, 0);
splitterRightWidget_->addWidget(enoughtSizeContainer_);
splitter_ = new QSplitter(Qt::Horizontal, pClass_);
sidePanel_ = new SidePanel(pClass_);
splitter_->addWidget(sidePanel_);
content_ = new ContentView(pClass_);
splitter_->addWidget(content_);
pClass_->layout()->addWidget(splitter_);
splitter_->addWidget(splitterRightWidget_);
connect(sidePanel_, SIGNAL(itemPicked(ModelPtr)),
this, SLOT(showAnItem(ModelPtr)));
......@@ -36,18 +55,132 @@ DocBookViewImpl::DocBookViewImpl(DocBookView *pClass)
connect(this, SIGNAL(itemSelected(ModelPtr)),
sidePanel_, SLOT(selectItem(ModelPtr)));
splitter_->setCollapsible(0, false);
splitter_->setCollapsible(1, false);
splitter_->move(0, 0);
toggleSideBar_ = new QLabel(pClass_);
toggleSideBar_->setFixedHeight(24);
toggleSideBar_->move(0, 0);
toggleSideBar_->setTextFormat(Qt::RichText);
connect(toggleSideBar_, SIGNAL(linkActivated(QString)),
this, SLOT(handleShowSideBarButton(QString)));
createActions();
background_->setStyleSheet("background-color: rgba(0,0,0,192);");
sidePanel_->setAutoFillBackground(true);
splitter_->handle(1)->setAutoFillBackground(true);
}
void DocBookViewImpl::updateToggleSideBarButton()
{
static const QString Hide = tr("Hide side bar");
static const QString Show = tr("Show side bar");
const QString & text = isSideBarVisible() ? Hide : Show;
const QString action = isSideBarVisible() ? "#hide" : "#show";
const QString html = QString("<a href=\"%1\">%2</a>").arg(action).arg(text);
const int width = toggleSideBar_->fontMetrics().width(text) + 16;
toggleSideBar_->setText(html);
toggleSideBar_->setFixedWidth(width);
}
bool DocBookViewImpl::isSideBarVisible() const
{
return compactModeFlag_ ? splitter_->isVisible() : sidePanel_->isVisible();
}
void DocBookViewImpl::handleShowSideBarButton(const QString &action)
{
if (action=="#show") {
showSidePanel();
}
else if (action=="#hide") {
hideSidePanel();
}
}
void DocBookViewImpl::setSize(const QSize &size)
{
int minWidth = content_->minimumSizeHint().width() +
sidePanel_->minimumSizeHint().width();
splitter_->move(0, 0);
splitter_->resize(size);
smallSizeContainer_->move(0, 0);
smallSizeContainer_->resize(size);
background_->move(0, 0);
background_->resize(size);
if (size.width() < minWidth) {
switchToCompactMode();
}
else {
switchToEnoughtSizeMode();
}
updateToggleSideBarButton();
}
void DocBookViewImpl::switchToCompactMode(bool force)
{
if (compactModeFlag_ && !force)
return;
compactModeFlag_ = true;
splitterRightWidget_->setCurrentIndex(0);
smallSizeContainer_->layout()->addWidget(content_);
splitter_->setVisible(false);
updateToggleSideBarButton();
background_->setVisible(isSideBarVisible());
}
void DocBookViewImpl::switchToEnoughtSizeMode(bool force)
{
if (!compactModeFlag_ && !force)
return;
compactModeFlag_ = false;
splitterRightWidget_->setCurrentIndex(1);
enoughtSizeContainer_->layout()->addWidget(content_);
splitter_->setVisible(true);
updateToggleSideBarButton();
background_->setVisible(false);
}
void DocBookViewImpl::hideSidePanel()
{
if (compactModeFlag_)
splitter_->setVisible(false);
else
sidePanel_->setVisible(false);
updateToggleSideBarButton();
background_->setVisible(false);
enoughtSizeContainer_->layout()->setContentsMargins(0, 24, 0, 0);
}
void DocBookViewImpl::showSidePanel()
{
splitter_->setVisible(true);
sidePanel_->setVisible(true);
updateToggleSideBarButton();
background_->setVisible(compactModeFlag_);
enoughtSizeContainer_->layout()->setContentsMargins(0, 0, 0, 0);
}
QSize DocBookViewImpl::minimumSizeHint() const
{
return QSize(800, 500);
int minW = qMax(sidePanel_->minimumSizeHint().width(),
content_->minimumSizeHint().width());
int minH = qMax(sidePanel_->minimumSizeHint().height(),
content_->minimumSizeHint().height());
return QSize(minW, minH);
}
QSize DocBookViewImpl::sizeHint() const
{
return QSize(1000, 600);
return QSize(800, 600);
}
void DocBookViewImpl::updateSettings(ExtensionSystem::SettingsPtr settings, const QString &prefix)
......@@ -63,6 +196,7 @@ void DocBookViewImpl::saveState(ExtensionSystem::SettingsPtr settings, const QSt
settings->setValue(prefix + "/SplitterState",
splitter_->saveState());
sidePanel_->saveState(settings, prefix + "/SideBar");
settings->setValue(prefix + "/CompactMode", compactModeFlag_);
}
void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const QString &prefix)
......@@ -72,6 +206,11 @@ void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const
splitter_->restoreGeometry(settings->value(prefix + "/SplitterGeometry")
.toByteArray());
sidePanel_->restoreState(settings, prefix + "/SideBar");
setSize(pClass_->size());
if (settings->value(prefix + "/CompactMode").toBool())
switchToCompactMode(true);
else
switchToEnoughtSizeMode(true);
}
......
......@@ -11,6 +11,8 @@
#include <QSharedPointer>
#include <QTreeWidget>
#include <QSplitter>
#include <QLabel>
#include <QStackedWidget>
namespace DocBookViewer {
......@@ -43,6 +45,8 @@ public /* methods */:
QSize minimumSizeHint() const;
QSize sizeHint() const;
bool isSideBarVisible() const;
void createActions();
signals:
......@@ -51,6 +55,17 @@ signals:
public slots:
void showAnItem(ModelPtr model);
void showPrintDialog();
void hideSidePanel();
void showSidePanel();
void setSize(const QSize & size);
void switchToCompactMode(bool force=false);
void switchToEnoughtSizeMode(bool force=false);
private slots:
void updateToggleSideBarButton();
void handleShowSideBarButton(const QString & action);
private /* fields */:
DocBookView* pClass_;
......@@ -61,8 +76,17 @@ private /* fields */:
SidePanel * sidePanel_;
ContentView * content_;
QAction* actionToggleNavigationBar_;
QAction* actionShowPrintDialog_;
QAction * actionToggleNavigationBar_;
QAction * actionShowPrintDialog_;
QLabel * toggleSideBar_;
QWidget * enoughtSizeContainer_;
QWidget * smallSizeContainer_;
QWidget * filler_;
QWidget * background_;
QStackedWidget * splitterRightWidget_;
bool compactModeFlag_;
};
......
......@@ -6,13 +6,19 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>480</height>
<width>200</width>
<height>261</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>250</width>
<width>200</width>
<height>0</height>
</size>
</property>
......@@ -20,38 +26,45 @@
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
<widget class="QFrame" name="frame">
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="contents">
<property name="spacing">
<number>0</number>
</property>
<item row="2" column="0">
<widget class="QPushButton" name="examples">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Contents</string>
<string>Examples</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="algorithms">
<item row="2" column="1">
<widget class="QPushButton" name="tables">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Algorithms</string>
<string>Tables</string>
</property>
<property name="checkable">
<bool>true</bool>
......@@ -59,25 +72,51 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="examples">
<widget class="QPushButton" name="contents">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Examples</string>
<string>Contents</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="tables">
<widget class="QPushButton" name="algorithms">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Tables</string>
<string>Algorithms</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="minimumSize">
<size>
<width>0</width>
<height>28</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
......@@ -85,6 +124,12 @@
<widget class="QStackedWidget" name="stackedWidget">
<widget class="QWidget" name="pageContents">
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
......@@ -104,6 +149,9 @@
</item>
<item>
<widget class="QTreeWidget" name="contentsNavigator">
<property name="indentation">
<number>10</number>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
......@@ -118,6 +166,12 @@
</widget>
<widget class="QWidget" name="pageAlgorithms">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......@@ -137,6 +191,9 @@
</item>
<item>
<widget class="QTreeWidget" name="algorithmsNavigator">
<property name="indentation">
<number>10</number>
</property>
<attribute name="headerVisible">
<bool>false</bool>
</attribute>
......@@ -151,6 +208,12 @@
</widget>
<widget class="QWidget" name="pageExamples">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
......@@ -170,6 +233,9 @@
</item>
<item>
<widget class="QTreeWidget" name="examplesNavigator">
<property name="indentation">
<number>10</number>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
......@@ -184,6 +250,12 @@
</widget>
<widget class="QWidget" name="pageTables">
<layout class="QVBoxLayout" name="verticalLayout_5">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
......@@ -203,6 +275,9 @@
</item>
<item>
<widget class="QTreeWidget" name="tablesNavigator">
<property name="indentation">
<number>10</number>
</property>
<property name="headerHidden">
<bool>true</bool>
</property>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment