Skip to content

Commit

Permalink
Add help buttons to dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Abs62 committed Jun 24, 2014
1 parent d4c68d3 commit 3531a74
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 15 deletions.
8 changes: 8 additions & 0 deletions config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,14 @@ QString getLocDir() throw()
return QCoreApplication::applicationDirPath() + "/locale";
}

QString getHelpDir() throw()
{
if ( QDir( getProgramDataDir() ).cd( "help" ) )
return getProgramDataDir() + "/help";
else
return QCoreApplication::applicationDirPath() + "/help";
}

bool isPortableVersion() throw()
{
struct IsPortable
Expand Down
3 changes: 3 additions & 0 deletions config.hh
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ QString getProgramDataDir() throw();
/// Returns the directory storing program localizized files (.qm).
QString getLocDir() throw();

/// Returns the directory storing program help files (.qch).
QString getHelpDir() throw();

/// Returns true if the program is configured as a portable version. In that
/// mode, all the settings and indices are kept in the program's directory.
bool isPortableVersion() throw();
Expand Down
20 changes: 20 additions & 0 deletions dictheadwords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "dictheadwords.hh"
#include "gddebug.hh"
#include "mainwindow.hh"

#include <QRegExp>
#include <QDir>
Expand All @@ -17,6 +18,7 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_,
QDialog(parent)
, cfg( cfg_ )
, dict( dict_ )
, helpAction( this )
{
ui.setupUi( this );

Expand Down Expand Up @@ -83,6 +85,17 @@ DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_,
connect( proxy, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ),
this, SLOT( showHeadwordsNumber() ) );

connect( ui.helpButton, SIGNAL( clicked() ),
this, SLOT( helpRequested() ) );

helpAction.setShortcut( QKeySequence( "F1" ) );
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( &helpAction, SIGNAL( triggered() ),
this, SLOT( helpRequested() ) );

addAction( &helpAction );

ui.headersListView->installEventFilter( this );

setup( dict_ );
Expand Down Expand Up @@ -304,3 +317,10 @@ void DictHeadwords::saveHeadersToFile()
gdWarning( "Headers export error: %s", file.errorString().toUtf8().data() );
file.close();
}

void DictHeadwords::helpRequested()
{
MainWindow * mainWindow = qobject_cast< MainWindow * >( parentWidget() );
if( mainWindow )
mainWindow->showGDHelpForID( "Dictionary headwords" );
}
5 changes: 5 additions & 0 deletions dictheadwords.hh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
#include <QStringList>
#include <QStringListModel>
#include <QSortFilterProxyModel>
#include <QAction>

#include "config.hh"
#include "ui_dictheadwords.h"
#include "dictionary.hh"
#include "delegate.hh"
#include "helpwindow.hh"

class DictHeadwords : public QDialog
{
Expand All @@ -32,6 +34,8 @@ protected:
QSortFilterProxyModel * proxy;
WordListItemDelegate * delegate;

QAction helpAction;

void saveHeadersToFile();
bool eventFilter( QObject * obj, QEvent * ev );

Expand All @@ -47,6 +51,7 @@ private slots:
void autoApplyStateChanged( int state );
void showHeadwordsNumber();
virtual void reject();
void helpRequested();

signals:
void headwordSelected( QString const & );
Expand Down
10 changes: 10 additions & 0 deletions dictheadwords.ui
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="helpButton">
<property name="text">
<string>Help</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="OKButton">
<property name="text">
Expand Down
50 changes: 50 additions & 0 deletions editdictionaries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "editdictionaries.hh"
#include "loaddictionaries.hh"
#include "dictinfo.hh"
#include "mainwindow.hh"
#include <QMessageBox>

using std::vector;
Expand All @@ -23,6 +24,8 @@ EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_,
dictionariesChanged( false ),
groupsChanged( false ),
lastCurrentTab( 0 )
, helpWindow( 0 )
, helpAction( this )
{
// Some groups may have contained links to non-existnent dictionaries. We
// would like to preserve them if no edits were done. To that end, we save
Expand Down Expand Up @@ -52,6 +55,18 @@ EditDictionaries::EditDictionaries( QWidget * parent, Config::Class & cfg_,

connect( orderAndProps.get(), SIGNAL( showDictionaryHeadwords( QString const & ) ),
this, SIGNAL( showDictionaryHeadwords( QString const & ) ) );

connect( ui.buttons, SIGNAL( helpRequested() ),
this, SLOT( helpRequested() ) );

helpAction.setShortcut( QKeySequence( "F1" ) );
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( &helpAction, SIGNAL( triggered() ),
this, SLOT( helpRequested() ) );

addAction( &helpAction );

}

void EditDictionaries::editGroup( unsigned id )
Expand Down Expand Up @@ -241,3 +256,38 @@ void EditDictionaries::acceptChangedSources( bool rebuildGroups )
origCfg.inactiveDictionaries = orderAndProps->getCurrentInactiveDictionaries();
}
}

void EditDictionaries::helpRequested()
{
if( !helpWindow )
{
MainWindow * mainWindow = qobject_cast< MainWindow * >( parentWidget() );
if( mainWindow )
mainWindow->closeGDHelp();

helpWindow = new Help::HelpWindow( this, cfg );

if( helpWindow )
{
helpWindow->setWindowFlags( Qt::Window );

connect( helpWindow, SIGNAL( needClose() ),
this, SLOT( closeHelp() ) );
helpWindow->showHelpFor( "Manage dictionaries" );
helpWindow->show();
}
}
else
{
if( !helpWindow->isVisible() )
helpWindow->show();

helpWindow->activateWindow();
}
}

void EditDictionaries::closeHelp()
{
if( helpWindow )
helpWindow->hide();
}
13 changes: 12 additions & 1 deletion editdictionaries.hh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
#include "orderandprops.hh"
#include "groups.hh"
#include "instances.hh"
#include "helpwindow.hh"
#include <QNetworkAccessManager>
#include <QAction>

class EditDictionaries: public QDialog
{
Expand All @@ -24,6 +26,9 @@ public:
Instances::Groups & groupInstances, // We only clear those on rescan
QNetworkAccessManager & dictNetMgr );

~EditDictionaries()
{ if( helpWindow ) delete helpWindow; }

/// Instructs the dialog to position itself on editing the given group.
void editGroup( unsigned id );

Expand All @@ -47,6 +52,9 @@ private slots:

void rescanSources();

void helpRequested();
void closeHelp();

signals:

void showDictionaryInfo( QString const & dictId );
Expand Down Expand Up @@ -79,7 +87,10 @@ private:
bool dictionariesChanged;
bool groupsChanged;

int lastCurrentTab;
int lastCurrentTab;

Help::HelpWindow * helpWindow;
QAction helpAction;
};

#endif
2 changes: 1 addition & 1 deletion editdictionaries.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
Expand Down
20 changes: 20 additions & 0 deletions fulltextsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "fulltextsearch.hh"
#include "ftshelpers.hh"
#include "gddebug.hh"
#include "mainwindow.hh"

#include <QThreadPool>
#include <QIntValidator>
Expand Down Expand Up @@ -126,6 +127,7 @@ FullTextSearchDialog::FullTextSearchDialog( QWidget * parent,
groups( groups_ ),
group( 0 ),
ftsIdx( ftsidx )
, helpAction( this )
{
ui.setupUi( this );

Expand Down Expand Up @@ -192,6 +194,17 @@ FullTextSearchDialog::FullTextSearchDialog( QWidget * parent,
connect( ui.OKButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( ui.cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );

connect( ui.helpButton, SIGNAL( clicked() ),
this, SLOT( helpRequested() ) );

helpAction.setShortcut( QKeySequence( "F1" ) );
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( &helpAction, SIGNAL( triggered() ),
this, SLOT( helpRequested() ) );

addAction( &helpAction );

ui.headwordsView->installEventFilter( this );

delegate = new WordListItemDelegate( ui.headwordsView->itemDelegate() );
Expand Down Expand Up @@ -483,6 +496,13 @@ bool FullTextSearchDialog::eventFilter( QObject * obj, QEvent * ev )
return QDialog::eventFilter( obj, ev );
}

void FullTextSearchDialog::helpRequested()
{
MainWindow * mainWindow = qobject_cast< MainWindow * >( parentWidget() );
if( mainWindow )
mainWindow->showGDHelpForID( "Full-text search" );
}

/// HeadwordsListModel

int HeadwordsListModel::rowCount( QModelIndex const & ) const
Expand Down
2 changes: 2 additions & 0 deletions fulltextsearch.hh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private:
QList< FtsHeadword > results;
HeadwordsListModel * model;
WordListItemDelegate * delegate;
QAction helpAction;

void showDictNumbers();

Expand All @@ -212,6 +213,7 @@ private slots:
void reject();
void itemClicked( QModelIndex const & idx );
void updateDictionaries();
void helpRequested();

signals:
void showTranslationFor( QString const &, QStringList const & dictIDs,
Expand Down
20 changes: 20 additions & 0 deletions fulltextsearch.ui
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="helpButton">
<property name="text">
<string>Help</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
Expand Down
Binary file modified help/gdhelp_en.qch
Binary file not shown.
Binary file modified help/gdhelp_ru.qch
Binary file not shown.
14 changes: 11 additions & 3 deletions helpwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,14 @@ HelpWindow::HelpWindow( QWidget * parent, Config::Class & cfg_ ) :
if( localeName.isEmpty() )
localeName = QLocale::system().name();

helpFile = QDir::toNativeSeparators( Config::getProgramDataDir() + "/help/gdhelp_"
+ localeName.left( 2 ) + ".qch" );
QString helpDir = Config::getHelpDir();
helpFile = QDir::toNativeSeparators( helpDir + "/gdhelp_" + localeName + ".qch" );

if( !QFileInfo( helpFile ).isFile() )
helpFile = QDir::toNativeSeparators( Config::getProgramDataDir() + "/help/gdhelp_en.qch" );
helpFile = QDir::toNativeSeparators( helpDir + "/gdhelp_" + localeName.left( 2 ) + ".qch" );

if( !QFileInfo( helpFile ).isFile() )
helpFile = QDir::toNativeSeparators( helpDir + "/gdhelp_en.qch" );

helpCollectionFile = QDir::toNativeSeparators( Config::getConfigDir() + "gdhelp.qhc" );

Expand Down Expand Up @@ -195,6 +198,11 @@ void HelpWindow::accept()
emit needClose();
}

void HelpWindow::showHelpFor( QString const & keyword )
{
helpBrowser->showHelpForKeyword( keyword );
}

void HelpWindow::forwardEnabled( bool enabled )
{
navForward->setEnabled( enabled );
Expand Down
2 changes: 2 additions & 0 deletions helpwindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public:
QHelpEngine const * getHelpEngine()
{ return helpEngine; }

void showHelpFor( QString const & keyword );

public slots:
virtual void reject();
virtual void accept();
Expand Down
Loading

0 comments on commit 3531a74

Please sign in to comment.