mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Merge pull request #20 from VVSiz/review/hide_statusbar
Crome-like status bar
This commit is contained in:
commit
d9d5c85871
|
@ -166,7 +166,8 @@ HEADERS += folding.hh \
|
|||
parsecmdline.hh \
|
||||
dictspanewidget.hh \
|
||||
maintabwidget.hh \
|
||||
dprintf.hh
|
||||
dprintf.hh \
|
||||
mainstatusbar.hh
|
||||
FORMS += groups.ui \
|
||||
dictgroupwidget.ui \
|
||||
mainwindow.ui \
|
||||
|
@ -251,7 +252,8 @@ SOURCES += folding.cc \
|
|||
about.cc \
|
||||
programs.cc \
|
||||
parsecmdline.cc \
|
||||
maintabwidget.cc
|
||||
maintabwidget.cc \
|
||||
mainstatusbar.cc
|
||||
win32 {
|
||||
SOURCES += mouseover_win32/ThTypes.c
|
||||
HEADERS += mouseover_win32/ThTypes.h
|
||||
|
|
105
mainstatusbar.cc
Normal file
105
mainstatusbar.cc
Normal file
|
@ -0,0 +1,105 @@
|
|||
/* This file is (c) 2011 Tvangeste <i.4m.l33t@yandex.ru>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include "mainstatusbar.hh"
|
||||
|
||||
#include <Qt>
|
||||
#include <QFrame>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDebug>
|
||||
#include <QEvent>
|
||||
|
||||
MainStatusBar::MainStatusBar(QWidget *parent) : QFrame(parent)
|
||||
{
|
||||
// style
|
||||
setWindowFlags( Qt::Tool | Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint );
|
||||
setFrameStyle( QFrame::Box | QFrame::Plain );
|
||||
setLineWidth(0);
|
||||
|
||||
// components
|
||||
label = new QLabel(QString(), this);
|
||||
label->setTextFormat(Qt::PlainText);
|
||||
timer = new QTimer(this);
|
||||
|
||||
// layout
|
||||
QVBoxLayout * layout = new QVBoxLayout;
|
||||
layout->addWidget(label);
|
||||
layout->setSizeConstraint(QLayout::SetFixedSize);
|
||||
layout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
layout->setMargin(4);
|
||||
setLayout(layout);
|
||||
|
||||
parentWidget()->installEventFilter( this );
|
||||
|
||||
connect( timer, SIGNAL( timeout() ), SLOT( clearMessage() ) );
|
||||
}
|
||||
|
||||
void MainStatusBar::clearMessage()
|
||||
{
|
||||
message = QString();
|
||||
label->setText(message);
|
||||
timer->stop();
|
||||
refresh();
|
||||
}
|
||||
|
||||
QString MainStatusBar::currentMessage() const
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
void MainStatusBar::showMessage(const QString & str, int timeout)
|
||||
{
|
||||
message = str;
|
||||
|
||||
if ( timeout > 0 )
|
||||
{
|
||||
timer->start( timeout );
|
||||
}
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void MainStatusBar::refresh()
|
||||
{
|
||||
|
||||
if ( !message.isEmpty() )
|
||||
{
|
||||
QRect pGeom = parentWidget()->geometry();
|
||||
|
||||
int maxLabelLength = pGeom.width() - 2 * layout()->margin();
|
||||
label->setText( label->fontMetrics().elidedText( message, Qt::ElideRight, maxLabelLength ) );
|
||||
|
||||
adjustSize();
|
||||
|
||||
move(pGeom.left(), pGeom.bottom() - size().height() + 1 );
|
||||
show();
|
||||
}
|
||||
else
|
||||
{
|
||||
hide();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void MainStatusBar::mousePressEvent ( QMouseEvent * )
|
||||
{
|
||||
clearMessage();
|
||||
}
|
||||
|
||||
bool MainStatusBar::eventFilter(QObject *, QEvent * event)
|
||||
{
|
||||
switch ( event->type() ) {
|
||||
case QEvent::Move:
|
||||
case QEvent::Resize:
|
||||
case QEvent::FocusOut:
|
||||
case QEvent::WindowDeactivate:
|
||||
case QEvent::Hide:
|
||||
case QEvent::WindowActivate:
|
||||
refresh();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
return false;
|
||||
}
|
37
mainstatusbar.hh
Normal file
37
mainstatusbar.hh
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* This file is (c) 2011 Tvangeste <i.4m.l33t@yandex.ru>
|
||||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#ifndef MAINSTATUSBAR_HH
|
||||
#define MAINSTATUSBAR_HH
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QString>
|
||||
#include <QTimer>
|
||||
|
||||
class MainStatusBar : public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainStatusBar(QWidget * parent);
|
||||
QString currentMessage() const;
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
void showMessage(const QString & text, int timeout = 0);
|
||||
void clearMessage();
|
||||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent * event);
|
||||
|
||||
private:
|
||||
QLabel * label;
|
||||
QTimer * timer;
|
||||
QString message;
|
||||
bool eventFilter(QObject *obj, QEvent * event);
|
||||
void refresh();
|
||||
};
|
||||
|
||||
#endif // MAINSTATUSBAR_HH
|
|
@ -16,6 +16,7 @@
|
|||
#include <set>
|
||||
#include <map>
|
||||
#include "dprintf.hh"
|
||||
#include <QDebug>
|
||||
|
||||
using std::set;
|
||||
using std::wstring;
|
||||
|
@ -55,6 +56,10 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
ui.setupUi( this );
|
||||
|
||||
// use our own, cutsom statusbar
|
||||
setStatusBar(0);
|
||||
mainStatusBar = new MainStatusBar( this );
|
||||
|
||||
wordListDefaultFont = ui.wordList->font();
|
||||
translateLineDefaultFont = ui.translateLine->font();
|
||||
|
||||
|
@ -465,6 +470,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
// makeDictionaries() didn't do deferred init - we do it here, at the end.
|
||||
doDeferredInit( dictionaries );
|
||||
|
||||
updateStatusLine();
|
||||
}
|
||||
|
||||
void MainWindow::mousePressEvent( QMouseEvent *event)
|
||||
|
@ -684,9 +691,9 @@ void MainWindow::updateStatusLine()
|
|||
wordCount += dictionaries[ x ]->getWordCount();
|
||||
}
|
||||
|
||||
statusBar()->showMessage( tr( "%1 dictionaries, %2 articles, %3 words" ).
|
||||
mainStatusBar->showMessage( tr( "%1 dictionaries, %2 articles, %3 words" ).
|
||||
arg( dictionaries.size() ).arg( articleCount ).
|
||||
arg( wordCount ) );
|
||||
arg( wordCount ), 10000 );
|
||||
}
|
||||
|
||||
void MainWindow::updateGroupList()
|
||||
|
@ -1244,8 +1251,10 @@ void MainWindow::translateInputChanged( QString const & newValue )
|
|||
{
|
||||
// If there's some status bar message present, clear it since it may be
|
||||
// about the previous search that has failed.
|
||||
if ( !statusBar()->currentMessage().isEmpty() )
|
||||
statusBar()->clearMessage();
|
||||
if ( !mainStatusBar->currentMessage().isEmpty() )
|
||||
{
|
||||
mainStatusBar->clearMessage();
|
||||
}
|
||||
|
||||
// If some word is selected in the word list, unselect it. This prevents
|
||||
// triggering a set of spurious activation signals when the list changes.
|
||||
|
@ -1401,7 +1410,7 @@ void MainWindow::updateMatchResults( bool finished )
|
|||
}
|
||||
|
||||
if ( !wordFinder.getErrorString().isEmpty() )
|
||||
statusBar()->showMessage( tr( "WARNING: %1" ).arg( wordFinder.getErrorString() ) );
|
||||
mainStatusBar->showMessage( tr( "WARNING: %1" ).arg( wordFinder.getErrorString() ), 20000 );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2024,14 +2033,17 @@ void MainWindow::toggleMenuBarTriggered(bool announce)
|
|||
{
|
||||
cfg.preferences.hideMenubar = menuBar()->isVisible();
|
||||
|
||||
if ( announce && cfg.preferences.hideMenubar )
|
||||
if ( announce )
|
||||
{
|
||||
statusBar()->showMessage(
|
||||
tr( "You have chosen to hide a menubar. Use %1 to show it back." ).arg( tr( "Ctl+M" ) ), 10000 );
|
||||
if ( cfg.preferences.hideMenubar )
|
||||
{
|
||||
mainStatusBar->showMessage(
|
||||
tr( "You have chosen to hide a menubar. Use %1 to show it back." ).arg( tr( "Ctrl+M" ) ), 10000 );
|
||||
}
|
||||
else
|
||||
{
|
||||
statusBar()->clearMessage();
|
||||
mainStatusBar->clearMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Obtain from the menubar all the actions with shortcuts
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "dictionarybar.hh"
|
||||
#include "history.hh"
|
||||
#include "hotkeywrapper.hh"
|
||||
#include "mainstatusbar.hh"
|
||||
|
||||
#ifdef Q_WS_X11
|
||||
#include <fixx11h.h>
|
||||
|
@ -73,6 +74,7 @@ private:
|
|||
switchToNextTabAction, switchToPrevTabAction,
|
||||
showDictBarNamesAction, useSmallIconsInToolbarsAction, toggleMenuBarAction;
|
||||
QToolBar * navToolbar;
|
||||
MainStatusBar * mainStatusBar;
|
||||
QAction * navBack, * navForward, * navPronounce, * enableScanPopup, * scanPopupSeparator;
|
||||
QAction * zoomIn, * zoomOut, * zoomBase;
|
||||
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
||||
|
|
|
@ -18,11 +18,14 @@
|
|||
<property name="leftMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>1</number>
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="MainTabWidget" name="tabWidget">
|
||||
|
@ -118,7 +121,6 @@
|
|||
<addaction name="menuHistory"/>
|
||||
<addaction name="menu_Help"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<widget class="QDockWidget" name="searchPane">
|
||||
<property name="windowTitle">
|
||||
<string>Search Pane</string>
|
||||
|
|
Loading…
Reference in a new issue