MenuTitle.h
Go to the documentation of this file.
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2 
3 /*
4  Sonic Visualiser
5  An audio file viewer and annotation editor.
6  Centre for Digital Music, Queen Mary, University of London.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version. See the file
12  COPYING included with this distribution for more information.
13 */
14 
15 #ifndef SV_MENU_TITLE_H
16 #define SV_MENU_TITLE_H
17 
18 #include "view/ViewManager.h"
19 
20 #include <QStyle>
21 #include <QWidgetAction>
22 #include <QLabel>
23 #include <QApplication>
24 #include <QMenu>
25 
26 class MenuTitle
27 {
28 public:
29  static void addTitle(QMenu *m, QString text) {
30 
31 #ifdef Q_OS_LINUX
32  static int leftIndent =
34  qApp->style()->pixelMetric(QStyle::PM_SmallIconSize));
35 #else
36 #ifdef Q_OS_WIN
37  static int leftIndent =
38  (9 + qApp->style()->pixelMetric(QStyle::PM_SmallIconSize));
39 #else
40  static int leftIndent = 16;
41 #endif
42 #endif
43 
44  QWidgetAction *wa = new QWidgetAction(m);
45  QLabel *title = new QLabel;
46  title->setText(QObject::tr("<b>%1</b>")
47  .arg(XmlExportable::encodeEntities(text)));
48  title->setMargin(ViewManager::scalePixelSize(3));
49  title->setIndent(leftIndent);
50  wa->setDefaultWidget(title);
51  m->addAction(wa);
52  m->addSeparator();
53  }
54 };
55 
56 #endif
static void addTitle(QMenu *m, QString text)
Definition: MenuTitle.h:29
static int scalePixelSize(int pixels)
Take a "design pixel" size and scale it for the actual display.