1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
* Cantata
*
* Copyright (c) 2011-2022 Craig Drummond <craig.p.drummond@gmail.com>
*
* ----
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "application.h"
#include "models/mpdlibrarymodel.h"
#include "models/playlistsmodel.h"
#include "models/streamsmodel.h"
#include "mpd-interface/mpdstats.h"
#include "mpd-interface/mpdstatus.h"
#include "settings.h"
#include "support/proxystyle.h"
#include "support/thread.h"
#include "support/utils.h"
#include "tags/taghelperiface.h"
#include <QListView>
#ifdef ENABLE_SCROBBLING
#include "scrobbling/scrobbler.h"
#endif
#include "config.h"
#include "http/httpserver.h"
#include "network/networkproxyfactory.h"
#include "support/combobox.h"
#include "support/fancytabwidget.h"
#include "widgets/actionitemdelegate.h"
#include "widgets/groupedview.h"
#include "widgets/itemview.h"
#include "widgets/sizegrip.h"
#include "widgets/toolbutton.h"
void Application::init()
{
#if defined Q_OS_WIN
ProxyStyle* proxy = new ProxyStyle(ProxyStyle::VF_Side);
#elif defined Q_OS_MAC
ProxyStyle* proxy = new ProxyStyle(ProxyStyle::VF_Side | ProxyStyle::VF_Top);
#else
ProxyStyle* proxy = new ProxyStyle(0);
#endif
QString theme = Settings::self()->style();
if (!theme.isEmpty()) {
QStyle* s = QApplication::setStyle(theme);
if (s) {
proxy->setBaseStyle(s);
}
}
qApp->setStyle(proxy);
#ifdef Q_OS_WIN
// Qt does not seem to consistently apply the application font under Windows.
// To work-around this, set the application font to that used for a listview.
// Issues #1097 and #1109
QListView view;
view.ensurePolished();
QApplication::setFont(view.font());
#endif
// Ensure these objects are created in the GUI thread...
ThreadCleaner::self();
MPDStatus::self();
MPDStats::self();
#ifdef ENABLE_TAGLIB
TagHelperIface::self();
#endif
NetworkProxyFactory::self();
#ifdef ENABLE_SCROBBLING
Scrobbler::self();
#endif
MpdLibraryModel::self();
PlaylistsModel::self();
StreamsModel::self();
// Ensure this is started before any MPD connection
HttpServer::self();
Song::initTranslations();
// Init sizes (before any widgets constructed!)
ItemView::setup();
FancyTabWidget::setup();
GroupedView::setup();
ActionItemDelegate::setup();
}
void Application::fixSize(QWidget* widget)
{
static int fixedHeight = -1;
if (-1 == fixedHeight) {
ComboBox c(widget);
ToolButton b(widget);
SizeGrip g(widget);
c.ensurePolished();
b.ensurePolished();
g.ensurePolished();
fixedHeight = qMax(24, qMax(c.sizeHint().height(), qMax(b.sizeHint().height(), g.sizeHint().height())));
if (fixedHeight % 2) {
fixedHeight--;
}
}
QToolButton* tb = qobject_cast<QToolButton*>(widget);
if (tb) {
tb->setFixedSize(fixedHeight, fixedHeight);
}
else {
#ifdef Q_OS_MAC
// TODO: Why is this +(2*focus) required for macOS? If its not used, library page's statusbar is larger
// than the rest - due to genre combo?
widget->setFixedHeight(fixedHeight + (2 * widget->style()->pixelMetric(QStyle::PM_FocusFrameHMargin)));
#else
if (0 == qstrcmp("QWidget", widget->metaObject()->className())) {
widget->setFixedHeight(fixedHeight + Utils::scaleForDpi(4));
}
else {
widget->setFixedHeight(fixedHeight);
}
#endif
}
}
|