Changeset - 654bf6056b56
[Not reviewed]
default
0 2 2
Hasan Yavuz ÖZDERYA - 10 years ago 2015-11-08 06:03:06
hy@ozderya.net
show keyboard shortcuts in tooltips
4 files changed with 93 insertions and 1 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -78,24 +78,25 @@ add_executable(${PROGRAM_NAME} WIN32
 
  framebuffer.cpp
 
  scalepicker.cpp
 
  scalezoomer.cpp
 
  portlist.cpp
 
  snapshot.cpp
 
  snapshotview.cpp
 
  snapshotmanager.cpp
 
  plotsnapshotoverlay.cpp
 
  commandpanel.cpp
 
  commandwidget.cpp
 
  commandedit.cpp
 
  dataformatpanel.cpp
 
  tooltipfilter.cpp
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  misc/windows_icon.rc
 
  )
 

	
 
# Use the Widgets module from Qt 5.
 
target_link_libraries(${PROGRAM_NAME} ${QWT_LIBRARY})
 
qt5_use_modules(${PROGRAM_NAME} Widgets SerialPort Svg)
 

	
 
# set compiler flags
 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
 

	
main.cpp
Show inline comments
 
@@ -8,42 +8,47 @@
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot 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 serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "mainwindow.h"
 
#include <QApplication>
 
#include <QtGlobal>
 

	
 
#include "mainwindow.h"
 
#include "tooltipfilter.h"
 
#include "version.h"
 

	
 

	
 
MainWindow* pMainWindow;
 

	
 
void messageHandler(QtMsgType type, const QMessageLogContext &context,
 
                    const QString &msg)
 
{
 
    // TODO: don't call MainWindow::messageHandler if window is destroyed
 
    pMainWindow->messageHandler(type, context, msg);
 
}
 

	
 
int main(int argc, char *argv[])
 
{
 
    QApplication a(argc, argv);
 
    MainWindow w;
 
    pMainWindow = &w;
 

	
 
    qInstallMessageHandler(messageHandler);
 

	
 
    ToolTipFilter ttf;
 
    a.installEventFilter(&ttf);
 

	
 
    // log application information
 
    qDebug() << "SerialPlot" << VERSION_STRING;
 
    qDebug() << "Revision" << VERSION_REVISION;
 

	
 
    w.show();
 
    return a.exec();
 
}
tooltipfilter.cpp
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot 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 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot 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 serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <QToolButton>
 
#include <QAction>
 
#include <QKeySequence>
 
#include <QHelpEvent>
 
#include <QToolTip>
 

	
 
#include "tooltipfilter.h"
 

	
 
bool ToolTipFilter::eventFilter(QObject *obj, QEvent *ev)
 
{
 
    if (ev->type() == QEvent::ToolTip && obj->inherits("QToolButton"))
 
    {
 
        // prepare tooltip message
 
        QToolButton* toolButton = (QToolButton*) obj;
 
        QAction* action = toolButton->defaultAction();
 
        QString toolTip = action->toolTip();
 

	
 
        if (toolTip.isEmpty()) return false;
 

	
 
        QKeySequence keys = action->shortcut();
 
        if (!keys.isEmpty())
 
        {
 
            toolTip += QString(" <b>[") + keys.toString() + "]</b>";
 
        }
 

	
 
        // show tooltip message
 
        QHelpEvent *helpEvent = static_cast<QHelpEvent *>(ev);
 
        QToolTip::showText(helpEvent->globalPos(), toolTip);
 
        return true;
 
    }
 
    else
 
    {
 
        return QObject::eventFilter(obj, ev);
 
    }
 
}
tooltipfilter.h
Show inline comments
 
new file 100644
 
/*
 
  Copyright © 2015 Hasan Yavuz Özderya
 

	
 
  This file is part of serialplot.
 

	
 
  serialplot 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 3 of the License, or
 
  (at your option) any later version.
 

	
 
  serialplot 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 serialplot.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef TOOLTIPFILTER_H
 
#define TOOLTIPFILTER_H
 

	
 
#include <QObject>
 
#include <QEvent>
 

	
 
class ToolTipFilter : public QObject
 
{
 
protected:
 
    bool eventFilter(QObject *obj, QEvent *ev);
 
};
 

	
 
#endif /* TOOLTIPFILTER_H */
0 comments (0 inline, 0 general)