Moved help browser from MainPage to a new base class named FloatingHelpBrowser for global usage.

Added FloatingHelpBrowser to the option window (help text not including).
The help text can be specified for the ConfigPages in the method "helpText".

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6818 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2013-10-09 09:31:40 +00:00
parent fa6bc5fe39
commit a50c899ff3
24 changed files with 225 additions and 67 deletions

View file

@ -48,6 +48,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/FeedReader.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/FeedReader.png") ; }
virtual QString pageName() const { return tr("FeedReader") ; } virtual QString pageName() const { return tr("FeedReader") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void useProxyToggled(); void useProxyToggled();

View file

@ -70,6 +70,7 @@ class AudioInputConfig : public ConfigPage
virtual QPixmap iconPixmap() const { return QPixmap(":/images/talking_on.svg") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/talking_on.svg") ; }
virtual QString pageName() const { return tr("VOIP") ; } virtual QString pageName() const { return tr("VOIP") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void loadSettings(); void loadSettings();

View file

@ -1,61 +1,18 @@
#include <iostream>
#include <retroshare-gui/mainpage.h> #include <retroshare-gui/mainpage.h>
#include <QGraphicsBlurEffect> #include "common/FloatingHelpBrowser.h"
#include <QAbstractButton>
#include <QGraphicsDropShadowEffect>
MainPage::MainPage(QWidget *parent , Qt::WindowFlags flags ) : QWidget(parent, flags) MainPage::MainPage(QWidget *parent , Qt::WindowFlags flags ) : QWidget(parent, flags)
{ {
help_browser = NULL ; mHelpBrowser = NULL ;
}
class MyTextBrowser: public QTextBrowser
{
public:
MyTextBrowser(QWidget *parent,QAbstractButton *bt)
: QTextBrowser(parent),button(bt)
{
}
virtual void mousePressEvent ( QMouseEvent* )
{
hide() ;
button->setChecked(false) ;
}
protected:
QAbstractButton *button ;
};
void MainPage::showHelp(bool b)
{
help_browser->resize(size()*0.5) ;
help_browser->move(width()/2 - help_browser->width()/2,height()/2 - help_browser->height()/2);
help_browser->update() ;
std::cerr << "Toggling help to " << b << std::endl;
if(b)
help_browser->show() ;
else
help_browser->hide() ;
} }
void MainPage::registerHelpButton(QAbstractButton *button,const QString& help_html_txt) void MainPage::registerHelpButton(QAbstractButton *button,const QString& help_html_txt)
{ {
if(help_browser == NULL) if (mHelpBrowser == NULL)
{ {
help_browser = new MyTextBrowser(this,button) ; mHelpBrowser = new FloatingHelpBrowser(this, button) ;
QGraphicsDropShadowEffect * effect = new QGraphicsDropShadowEffect(help_browser) ;
effect->setBlurRadius(30.0);
help_browser->setGraphicsEffect(effect);
help_browser->setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum)) ;
help_browser->hide() ;
} }
help_browser->setHtml("<div align=\"justify\">"+help_html_txt+"</div>") ; mHelpBrowser->setHelpText(help_html_txt) ;
QObject::connect(button,SIGNAL(toggled(bool)), this, SLOT( showHelp(bool) ) ) ;
} }

View file

@ -0,0 +1,97 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2013, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#include <QGraphicsDropShadowEffect>
#include <QAbstractButton>
#include <QShowEvent>
#include <iostream>
#include "FloatingHelpBrowser.h"
FloatingHelpBrowser::FloatingHelpBrowser(QWidget *parent, QAbstractButton *button) :
QTextBrowser(parent), mButton(button)
{
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect(this);
effect->setBlurRadius(30.0);
setGraphicsEffect(effect);
setSizePolicy(QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum));
hide();
connect(this, SIGNAL(textChanged()), this, SLOT(textChanged()));
if (mButton) {
connect(mButton, SIGNAL(toggled(bool)), this, SLOT(showHelp(bool)));
}
}
void FloatingHelpBrowser::showEvent(QShowEvent */*event*/)
{
if (mButton) {
mButton->setChecked(true);
}
}
void FloatingHelpBrowser::hideEvent(QHideEvent */*event*/)
{
if (mButton) {
mButton->setChecked(false);
}
}
void FloatingHelpBrowser::mousePressEvent(QMouseEvent */*event*/)
{
hide();
}
void FloatingHelpBrowser::textChanged()
{
if (mButton) {
mButton->setVisible(!document()->isEmpty());
}
}
void FloatingHelpBrowser::showHelp(bool state)
{
QWidget *p = parentWidget();
if (!p) {
return;
}
resize(p->size() * 0.5);
move(p->width() / 2 - width() / 2, p->height() / 2 - height() / 2);
update();
std::cerr << "Toggling help to " << state << std::endl;
setVisible(state);
}
void FloatingHelpBrowser::setHelpText(const QString &helpText)
{
if (helpText.isEmpty()) {
clear();
return;
}
setHtml("<div align=\"justify\">" + helpText + "</div>");
}

View file

@ -0,0 +1,57 @@
/****************************************************************
* This file is distributed under the following license:
*
* Copyright (c) 2013, RetroShare Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
****************************************************************/
#ifndef FLOATINGHELPBROWSER_H
#define FLOATINGHELPBROWSER_H
#include <QTextBrowser>
class QAbstractButton;
class FloatingHelpBrowser : public QTextBrowser
{
Q_OBJECT
public:
explicit FloatingHelpBrowser(QWidget *parent, QAbstractButton *button);
void setHelpText(const QString &helpText);
public slots:
void showHelp(bool state);
private slots:
void textChanged();
protected:
virtual void showEvent(QShowEvent *event);
virtual void hideEvent(QHideEvent *event);
virtual void mousePressEvent(QMouseEvent *event);
protected:
using QTextBrowser::setHtml;
using QTextBrowser::setText;
private:
QAbstractButton *mButton;
};
#endif // FLOATINGHELPBROWSER_H

View file

@ -40,6 +40,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/looknfeel.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/looknfeel.png") ; }
virtual QString pageName() const { return tr("Appearance") ; } virtual QString pageName() const { return tr("Appearance") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void loadStyleSheet(int index); void loadStyleSheet(int index);

View file

@ -42,6 +42,7 @@ class ChatPage : public ConfigPage
virtual QPixmap iconPixmap() const { return QPixmap(":/images/chat_24.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/chat_24.png") ; }
virtual QString pageName() const { return tr("Chat") ; } virtual QString pageName() const { return tr("Chat") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void on_historyComboBoxVariant_currentIndexChanged(int index); void on_historyComboBoxVariant_currentIndexChanged(int index);
@ -80,4 +81,3 @@ class ChatPage : public ConfigPage
}; };
#endif #endif

View file

@ -41,6 +41,7 @@ class CryptoPage : public ConfigPage
virtual QPixmap iconPixmap() const { return QPixmap(":/images/encrypted32.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/encrypted32.png") ; }
virtual QString pageName() const { return tr("Profile") ; } virtual QString pageName() const { return tr("Profile") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
virtual void load(); virtual void load();

View file

@ -39,6 +39,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/folder_doments.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/folder_doments.png") ; }
virtual QString pageName() const { return tr("Directories") ; } virtual QString pageName() const { return tr("Directories") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void editDirectories() ; void editDirectories() ;

View file

@ -40,6 +40,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/konversation.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/konversation.png") ; }
virtual QString pageName() const { return tr("Forum") ; } virtual QString pageName() const { return tr("Forum") ; }
virtual QString helpText() const { return ""; }
private: private:
Ui::ForumPage ui; Ui::ForumPage ui;

View file

@ -43,6 +43,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/kcmsystem24.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/kcmsystem24.png") ; }
virtual QString pageName() const { return tr("General") ; } virtual QString pageName() const { return tr("General") ; }
virtual QString helpText() const { return ""; }
public slots: public slots:
void runStartWizard() ; void runStartWizard() ;

View file

@ -44,6 +44,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/evolution.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/evolution.png") ; }
virtual QString pageName() const { return tr("Message") ; } virtual QString pageName() const { return tr("Message") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:

View file

@ -69,6 +69,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/status_unknown.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/status_unknown.png") ; }
virtual QString pageName() const { return tr("Notify") ; } virtual QString pageName() const { return tr("Notify") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void notifyToggled(); void notifyToggled();

View file

@ -39,6 +39,7 @@ class PluginsPage : public ConfigPage
virtual QPixmap iconPixmap() const { return QPixmap(":/images/extension_32.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/extension_32.png") ; }
virtual QString pageName() const { return tr("Plugins") ; } virtual QString pageName() const { return tr("Plugins") ; }
virtual QString helpText() const { return ""; }
public slots: public slots:

View file

@ -42,6 +42,7 @@ class RelayPage: public ConfigPage
virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; }
virtual QString pageName() const { return tr("Relay") ; } virtual QString pageName() const { return tr("Relay") ; }
virtual QString helpText() const { return ""; }
public slots: public slots:
void updateRelayOptions(); void updateRelayOptions();

View file

@ -42,6 +42,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/server_24x24.png") ; }
virtual QString pageName() const { return tr("Server") ; } virtual QString pageName() const { return tr("Server") ; }
virtual QString helpText() const { return ""; }
public slots: public slots:
void updateStatus(); void updateStatus();

View file

@ -45,6 +45,7 @@ public:
virtual QPixmap iconPixmap() const { return QPixmap(":/images/sound.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/sound.png") ; }
virtual QString pageName() const { return tr("Sound") ; } virtual QString pageName() const { return tr("Sound") ; }
virtual QString helpText() const { return ""; }
private slots: private slots:
void eventChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous); void eventChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);

View file

@ -42,6 +42,7 @@ class TransferPage: public ConfigPage
virtual QPixmap iconPixmap() const { return QPixmap(":/images/ktorrent32.png") ; } virtual QPixmap iconPixmap() const { return QPixmap(":/images/ktorrent32.png") ; }
virtual QString pageName() const { return tr("Transfer") ; } virtual QString pageName() const { return tr("Transfer") ; }
virtual QString helpText() const { return ""; }
public slots: public slots:
void updateQueueSize(int) ; void updateQueueSize(int) ;

View file

@ -40,6 +40,7 @@
#include "PluginsPage.h" #include "PluginsPage.h"
#include "rsharesettings.h" #include "rsharesettings.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
#include "gui/common/FloatingHelpBrowser.h"
#define IMAGE_GENERAL ":/images/kcmsystem24.png" #define IMAGE_GENERAL ":/images/kcmsystem24.png"
@ -55,6 +56,9 @@ RSettingsWin::RSettingsWin(QWidget *parent)
setAttribute(Qt::WA_DeleteOnClose, true); setAttribute(Qt::WA_DeleteOnClose, true);
setModal(false); setModal(false);
/* Initialize help browser */
mHelpBrowser = new FloatingHelpBrowser(this, helpButton);
initStackedWidget(); initStackedWidget();
connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int))); connect(listWidget, SIGNAL(currentRowChanged(int)), this, SLOT(setNewPage(int)));
@ -160,9 +164,12 @@ RSettingsWin::setNewPage(int page)
{ {
ConfigPage *pagew = dynamic_cast<ConfigPage*>(stackedWidget->widget(page)) ; ConfigPage *pagew = dynamic_cast<ConfigPage*>(stackedWidget->widget(page)) ;
mHelpBrowser->hide();
if(pagew == NULL) if(pagew == NULL)
{ {
std::cerr << "Error in RSettingsWin::setNewPage(): widget is not a ConfigPage!" << std::endl; std::cerr << "Error in RSettingsWin::setNewPage(): widget is not a ConfigPage!" << std::endl;
mHelpBrowser->clear();
return ; return ;
} }
pageName->setText(pagew->pageName()); pageName->setText(pagew->pageName());
@ -170,6 +177,8 @@ RSettingsWin::setNewPage(int page)
stackedWidget->setCurrentIndex(page); stackedWidget->setCurrentIndex(page);
listWidget->setCurrentRow(page); listWidget->setCurrentRow(page);
mHelpBrowser->setHelpText(pagew->helpText());
} }
/** Saves changes made to settings. */ /** Saves changes made to settings. */

View file

@ -26,6 +26,8 @@
#include <retroshare-gui/configpage.h> #include <retroshare-gui/configpage.h>
#include "ui_settings.h" #include "ui_settings.h"
class FloatingHelpBrowser;
class RSettingsWin: public QDialog, private Ui::Settings class RSettingsWin: public QDialog, private Ui::Settings
{ {
Q_OBJECT Q_OBJECT
@ -56,6 +58,7 @@ private:
void initStackedWidget(); void initStackedWidget();
private: private:
FloatingHelpBrowser *mHelpBrowser;
static RSettingsWin *_instance; static RSettingsWin *_instance;
static int lastPage; static int lastPage;
}; };

View file

@ -84,19 +84,6 @@
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="pageicon">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="pageName"> <widget class="QLabel" name="pageName">
<property name="sizePolicy"> <property name="sizePolicy">
@ -117,7 +104,37 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="2"> <item row="0" column="0">
<widget class="QLabel" name="pageicon">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="helpButton">
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/64px_help.png</normaloff>:/images/64px_help.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="Line" name="line_2"> <widget class="Line" name="line_2">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>

View file

@ -457,6 +457,7 @@ HEADERS += rshare.h \
gui/common/HeaderFrame.h \ gui/common/HeaderFrame.h \
gui/common/MimeTextEdit.h \ gui/common/MimeTextEdit.h \
gui/common/UIStateHelper.h \ gui/common/UIStateHelper.h \
gui/common/FloatingHelpBrowser.h \
gui/style/RSStyle.h \ gui/style/RSStyle.h \
gui/style/StyleDialog.h \ gui/style/StyleDialog.h \
gui/MessagesDialog.h \ gui/MessagesDialog.h \
@ -738,6 +739,7 @@ SOURCES += main.cpp \
gui/common/HeaderFrame.cpp \ gui/common/HeaderFrame.cpp \
gui/common/MimeTextEdit.cpp \ gui/common/MimeTextEdit.cpp \
gui/common/UIStateHelper.cpp \ gui/common/UIStateHelper.cpp \
gui/common/FloatingHelpBrowser.cpp \
gui/style/RSStyle.cpp \ gui/style/RSStyle.cpp \
gui/style/StyleDialog.cpp \ gui/style/StyleDialog.cpp \
gui/settings/rsharesettings.cpp \ gui/settings/rsharesettings.cpp \

View file

@ -49,6 +49,10 @@ class ConfigPage : public QWidget
// //
virtual QString pageName() const = 0 ; virtual QString pageName() const = 0 ;
// Text to be used to display in the help browser
//
virtual QString helpText() const = 0;
protected: protected:
virtual void showEvent(QShowEvent * /*event*/) virtual void showEvent(QShowEvent * /*event*/)
{ {

View file

@ -28,6 +28,7 @@
class UserNotify; class UserNotify;
class QAbstractButton ; class QAbstractButton ;
class FloatingHelpBrowser;
class MainPage : public QWidget class MainPage : public QWidget
{ {
@ -45,11 +46,8 @@ class MainPage : public QWidget
// //
void registerHelpButton(QAbstractButton *button, const QString& help_html_text) ; void registerHelpButton(QAbstractButton *button, const QString& help_html_text) ;
private slots:
void showHelp(bool b) ;
private: private:
QTextBrowser *help_browser ; FloatingHelpBrowser *mHelpBrowser ;
}; };
#endif #endif