| 1 |
/* This file is part of the KDE project |
| 2 |
SPDX-FileCopyrightText: 2001 David Faure <[email protected]> |
| 3 |
SPDX-FileCopyrightText: 2003 Nicolas GOUTTE <[email protected]> |
| 4 |
SPDX-FileCopyrightText: 2009 Thomas Zander <[email protected]> |
| 5 |
|
| 6 |
SPDX-License-Identifier: LGPL-2.0-or-later |
| 7 |
*/ |
| 8 |
|
| 9 |
// clazy:excludeall=qstring-arg |
| 10 |
#include "KoDpi.h" |
| 11 |
|
| 12 |
#include <QFontInfo> |
| 13 |
|
| 14 |
#ifdef HAVE_X11 |
| 15 |
#include <QX11Info> |
| 16 |
#else |
| 17 |
#include <QApplication> |
| 18 |
#include <QScreen> |
| 19 |
#endif |
| 20 |
|
| 21 |
#include <QGlobalStatic> |
| 22 |
|
| 23 |
Q_GLOBAL_STATIC(KoDpi, s_instance) |
| 24 |
|
| 25 |
KoDpi* KoDpi::self() |
| 26 |
{ |
| 27 |
return s_instance; |
| 28 |
} |
| 29 |
|
| 30 |
KoDpi::KoDpi() |
| 31 |
{ |
| 32 |
// Another way to get the DPI of the display would be QPaintDeviceMetrics, |
| 33 |
// but we have no widget here (and moving this to KoView wouldn't allow |
| 34 |
// using this from the document easily). |
| 35 |
#ifdef HAVE_X11 |
| 36 |
m_dpiX = QX11Info::appDpiX(); |
| 37 |
m_dpiY = QX11Info::appDpiY(); |
| 38 |
#else |
| 39 |
QScreen *screen = QGuiApplication::primaryScreen(); |
| 40 |
if (screen) { |
| 41 |
m_dpiX = screen->logicalDotsPerInchX(); |
| 42 |
m_dpiY = screen->logicalDotsPerInchY(); |
| 43 |
} else { |
| 44 |
m_dpiX = 75; |
| 45 |
m_dpiY = 75; |
| 46 |
} |
| 47 |
#endif |
| 48 |
} |
| 49 |
|
| 50 |
KoDpi::~KoDpi() |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
void KoDpi::setDPI(int x, int y) |
| 55 |
{ |
| 56 |
//debugWidgets << x <<"," << y; |
| 57 |
KoDpi* s = self(); |
| 58 |
s->m_dpiX = x; |
| 59 |
s->m_dpiY = y; |
| 60 |
} |