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 { ...@@ -10,7 +10,7 @@ namespace DocBookViewer {
static const QString MainFontFamily = static const QString MainFontFamily =
"Droid Serif,PT Serif,Garamond,Times New Roman,serif"; "Droid Serif,PT Serif,Garamond,Times New Roman,serif";
static const QString MainFontSize = "14pt"; static const QString MainFontSize = "12pt";
static const QString CodeFontFamily = static const QString CodeFontFamily =
"DejaVu Sans Mono,Liberation Mono,PT Sans Mono,Courier New,monospace"; "DejaVu Sans Mono,Liberation Mono,PT Sans Mono,Courier New,monospace";
...@@ -23,11 +23,14 @@ ContentView::ContentView(QWidget *parent) ...@@ -23,11 +23,14 @@ ContentView::ContentView(QWidget *parent)
setOpenLinks(false); setOpenLinks(false);
connect(this, SIGNAL(anchorClicked(QUrl)), connect(this, SIGNAL(anchorClicked(QUrl)),
this, SLOT(handleInternalLink(QUrl))); this, SLOT(handleInternalLink(QUrl)));
connect(verticalScrollBar(), SIGNAL(sliderMoved(int)),
this, SLOT(clearLastAnchorUrl()));
ignoreClearAnchorUrl_ = false;
} }
QSize ContentView::minimumSizeHint() const QSize ContentView::minimumSizeHint() const
{ {
return QSize(500, 400); return QSize(500, 230);
} }
void ContentView::reset() void ContentView::reset()
...@@ -48,6 +51,7 @@ void ContentView::renderData(ModelPtr data) ...@@ -48,6 +51,7 @@ void ContentView::renderData(ModelPtr data)
QString anchor = modelToLink(data); QString anchor = modelToLink(data);
QUrl anchorUrl("#" + anchor); QUrl anchorUrl("#" + anchor);
setSource(anchorUrl); setSource(anchorUrl);
lastAnchorUrl_ = anchorUrl;
} }
} }
...@@ -1502,4 +1506,33 @@ QString ContentView::formatProgramSourceText( ...@@ -1502,4 +1506,33 @@ QString ContentView::formatProgramSourceText(
return result; 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 @@ ...@@ -6,6 +6,8 @@
#include <QtGlobal> #include <QtGlobal>
#include <QTextBrowser> #include <QTextBrowser>
#include <QSharedPointer> #include <QSharedPointer>
#include <QResizeEvent>
#include <QWheelEvent>
namespace DocBookViewer { namespace DocBookViewer {
...@@ -27,6 +29,9 @@ signals: ...@@ -27,6 +29,9 @@ signals:
void itemRequest(ModelPtr model); void itemRequest(ModelPtr model);
private: private:
void resizeEvent(QResizeEvent *e);
void wheelEvent(QWheelEvent *e);
QString wrapHTML(const QString & body) const; QString wrapHTML(const QString & body) const;
QString render(ModelPtr data) const; QString render(ModelPtr data) const;
QString renderElement(ModelPtr data) const; QString renderElement(ModelPtr data) const;
...@@ -123,8 +128,11 @@ private: ...@@ -123,8 +128,11 @@ private:
private /*fields*/: private /*fields*/:
ModelPtr loadedModel_; ModelPtr loadedModel_;
QUrl lastAnchorUrl_;
bool ignoreClearAnchorUrl_;
private slots: private slots:
void clearLastAnchorUrl();
void handleInternalLink(const QUrl & url); void handleInternalLink(const QUrl & url);
......
#include "docbookview.h" #include "docbookview.h"
#include "docbookview_impl.h" #include "docbookview_impl.h"
#include <QResizeEvent>
namespace DocBookViewer { namespace DocBookViewer {
DocBookView::DocBookView(QWidget *parent) DocBookView::DocBookView(QWidget *parent)
...@@ -39,6 +41,18 @@ void DocBookView::showEvent(QShowEvent * event) ...@@ -39,6 +41,18 @@ void DocBookView::showEvent(QShowEvent * event)
QWidget::showEvent(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() DocBookView::~DocBookView()
{ {
......
...@@ -56,6 +56,7 @@ protected: ...@@ -56,6 +56,7 @@ protected:
void showEvent(QShowEvent *); void showEvent(QShowEvent *);
void closeEvent(QCloseEvent *); void closeEvent(QCloseEvent *);
void hideEvent(QHideEvent *); void hideEvent(QHideEvent *);
void resizeEvent(QResizeEvent *);
private: private:
class DocBookViewImpl* pImpl_; class DocBookViewImpl* pImpl_;
......
...@@ -18,14 +18,33 @@ DocBookViewImpl::DocBookViewImpl(DocBookView *pClass) ...@@ -18,14 +18,33 @@ DocBookViewImpl::DocBookViewImpl(DocBookView *pClass)
: QObject(pClass) : QObject(pClass)
, pClass_(pClass) , pClass_(pClass)
, settings_(nullptr) , 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_); splitter_ = new QSplitter(Qt::Horizontal, pClass_);
sidePanel_ = new SidePanel(pClass_); sidePanel_ = new SidePanel(pClass_);
splitter_->addWidget(sidePanel_); splitter_->addWidget(sidePanel_);
content_ = new ContentView(pClass_); content_ = new ContentView(pClass_);
splitter_->addWidget(content_); splitter_->addWidget(splitterRightWidget_);
pClass_->layout()->addWidget(splitter_);
connect(sidePanel_, SIGNAL(itemPicked(ModelPtr)), connect(sidePanel_, SIGNAL(itemPicked(ModelPtr)),
this, SLOT(showAnItem(ModelPtr))); this, SLOT(showAnItem(ModelPtr)));
...@@ -36,18 +55,132 @@ DocBookViewImpl::DocBookViewImpl(DocBookView *pClass) ...@@ -36,18 +55,132 @@ DocBookViewImpl::DocBookViewImpl(DocBookView *pClass)
connect(this, SIGNAL(itemSelected(ModelPtr)), connect(this, SIGNAL(itemSelected(ModelPtr)),
sidePanel_, SLOT(selectItem(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(); 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 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 QSize DocBookViewImpl::sizeHint() const
{ {
return QSize(1000, 600); return QSize(800, 600);
} }
void DocBookViewImpl::updateSettings(ExtensionSystem::SettingsPtr settings, const QString &prefix) void DocBookViewImpl::updateSettings(ExtensionSystem::SettingsPtr settings, const QString &prefix)
...@@ -63,6 +196,7 @@ void DocBookViewImpl::saveState(ExtensionSystem::SettingsPtr settings, const QSt ...@@ -63,6 +196,7 @@ void DocBookViewImpl::saveState(ExtensionSystem::SettingsPtr settings, const QSt
settings->setValue(prefix + "/SplitterState", settings->setValue(prefix + "/SplitterState",
splitter_->saveState()); splitter_->saveState());
sidePanel_->saveState(settings, prefix + "/SideBar"); sidePanel_->saveState(settings, prefix + "/SideBar");
settings->setValue(prefix + "/CompactMode", compactModeFlag_);
} }
void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const QString &prefix) void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const QString &prefix)
...@@ -72,6 +206,11 @@ void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const ...@@ -72,6 +206,11 @@ void DocBookViewImpl::restoreState(ExtensionSystem::SettingsPtr settings, const
splitter_->restoreGeometry(settings->value(prefix + "/SplitterGeometry") splitter_->restoreGeometry(settings->value(prefix + "/SplitterGeometry")
.toByteArray()); .toByteArray());
sidePanel_->restoreState(settings, prefix + "/SideBar"); sidePanel_->restoreState(settings, prefix + "/SideBar");
setSize(pClass_->size());
if (settings->value(prefix + "/CompactMode").toBool())
switchToCompactMode(true);
else
switchToEnoughtSizeMode(true);
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QTreeWidget> #include <QTreeWidget>
#include <QSplitter> #include <QSplitter>
#include <QLabel>
#include <QStackedWidget>
namespace DocBookViewer { namespace DocBookViewer {
...@@ -43,6 +45,8 @@ public /* methods */: ...@@ -43,6 +45,8 @@ public /* methods */:
QSize minimumSizeHint() const; QSize minimumSizeHint() const;
QSize sizeHint() const; QSize sizeHint() const;
bool isSideBarVisible() const;
void createActions(); void createActions();
signals: signals:
...@@ -51,6 +55,17 @@ signals: ...@@ -51,6 +55,17 @@ signals:
public slots: public slots:
void showAnItem(ModelPtr model); void showAnItem(ModelPtr model);
void showPrintDialog(); 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 */: private /* fields */:
DocBookView* pClass_; DocBookView* pClass_;
...@@ -61,8 +76,17 @@ private /* fields */: ...@@ -61,8 +76,17 @@ private /* fields */:
SidePanel * sidePanel_; SidePanel * sidePanel_;
ContentView * content_; ContentView * content_;
QAction* actionToggleNavigationBar_; QAction * actionToggleNavigationBar_;
QAction* actionShowPrintDialog_; QAction * actionShowPrintDialog_;
QLabel * toggleSideBar_;
QWidget * enoughtSizeContainer_;
QWidget * smallSizeContainer_;
QWidget * filler_;
QWidget * background_;
QStackedWidget * splitterRightWidget_;
bool compactModeFlag_;
}; };
......
...@@ -6,13 +6,19 @@ ...@@ -6,13 +6,19 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>300</width> <width>200</width>
<height>480</height> <height>261</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>250</width> <width>200</width>
<height>0</height> <height>0</height>
</size> </size>
</property> </property>
...@@ -20,38 +26,45 @@ ...@@ -20,38 +26,45 @@
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="margin"> <property name="margin">
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QFrame" name="frame">
<property name="title">
<string/>
</property>
<property name="flat">
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<property name="margin"> <property name="margin">
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <property name="spacing">
<widget class="QPushButton" name="contents"> <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"> <property name="text">
<string>Contents</string> <string>Examples</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="algorithms"> <widget class="QPushButton" name="tables">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text"> <property name="text">
<string>Algorithms</string> <string>Tables</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
...@@ -59,25 +72,51 @@ ...@@ -59,25 +72,51 @@
</widget> </widget>
</item> </item>
<item row="1" column="0"> <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"> <property name="text">
<string>Examples</string> <string>Contents</string>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>