annotate widgets/MenuTitle.h @ 1583:2e720fdcab0a

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