include/katie/QtGui/QCloseEvent
include/katie/QtGui/QColor
include/katie/QtGui/QColorDialog
-include/katie/QtGui/QColormap
include/katie/QtGui/QColumnView
include/katie/QtGui/QComboBox
include/katie/QtGui/QCommandLinkButton
include/katie/QtGui/qclipboard.h
include/katie/QtGui/qcolor.h
include/katie/QtGui/qcolordialog.h
-include/katie/QtGui/qcolormap.h
include/katie/QtGui/qcolumnview.h
include/katie/QtGui/qcombobox.h
include/katie/QtGui/qcommandlinkbutton.h
include/katie/QtGui/QCloseEvent
include/katie/QtGui/QColor
include/katie/QtGui/QColorDialog
-include/katie/QtGui/QColormap
include/katie/QtGui/QColumnView
include/katie/QtGui/QComboBox
include/katie/QtGui/QCommandLinkButton
include/katie/QtGui/qclipboard.h
include/katie/QtGui/qcolor.h
include/katie/QtGui/qcolordialog.h
-include/katie/QtGui/qcolormap.h
include/katie/QtGui/qcolumnview.h
include/katie/QtGui/qcombobox.h
include/katie/QtGui/qcommandlinkbutton.h
include/katie/QtGui/QCloseEvent
include/katie/QtGui/QColor
include/katie/QtGui/QColorDialog
-include/katie/QtGui/QColormap
include/katie/QtGui/QColumnView
include/katie/QtGui/QComboBox
include/katie/QtGui/QCommandLinkButton
include/katie/QtGui/qclipboard.h
include/katie/QtGui/qcolor.h
include/katie/QtGui/qcolordialog.h
-include/katie/QtGui/qcolormap.h
include/katie/QtGui/qcolumnview.h
include/katie/QtGui/qcombobox.h
include/katie/QtGui/qcommandlinkbutton.h
"QCloseEvent",
"QColor",
"QColorDialog",
- "QColormap",
"QColumnView",
"QComboBox",
"QCommandLinkButton",
QClipboard
QColor
QColorDialog
- QColormap
QColumnView
QComboBox
QCommandLinkButton
${CMAKE_CURRENT_SOURCE_DIR}/painting/qbrush.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcolor.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcolor_p.h
- ${CMAKE_CURRENT_SOURCE_DIR}/painting/qcolormap.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcssutil_p.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qdrawutil.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qmatrix.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qbackingstore.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qprinterinfo_unix.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qgrayraster.c
- ${CMAKE_CURRENT_SOURCE_DIR}/painting/qcolormap_x11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qpaintengine_x11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/styles/qstyle.cpp
${CMAKE_CURRENT_SOURCE_DIR}/styles/qstylefactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/qx11info_x11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/kernel/qt_x11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qbackingstore.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/painting/qcolormap_x11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qpaintengine_x11.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qregion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qwindowsurface.cpp
#include "qimagewriter.h"
#include "qstringlist.h"
#include "qvariant.h"
-#include "qcolormap.h"
#include "qdrawhelper_p.h"
#include "qmemrotate_p.h"
#include "qpixmapdata_p.h"
QImage::Format QImage::systemFormat()
{
#if defined(Q_WS_X11)
- if (QColormap::instance().depth() == 16)
+ if (QX11Info::appDepth() == 16)
return QImage::Format_RGB16;
#endif
return QImage::Format_RGB32;
#include "qpixmap.h"
#include "qpixmapdata_p.h"
#include "qbitmap.h"
-#include "qcolormap.h"
#include "qimage.h"
#include "qwidget.h"
#include "qpainter.h"
On X11 and the depth of the screen will be returned by this
function.
- \sa depth(), QColormap::depth(), {QPixmap#Pixmap Information}{Pixmap Information}
+ \sa depth(), QX11Info::appDepth(), {QPixmap#Pixmap Information}{Pixmap Information}
*/
int QPixmap::defaultDepth()
{
-#if defined(Q_WS_X11)
return QX11Info::appDepth();
-#endif
}
/*!
#include "qiodevice.h"
#include "qpixmap_x11_p.h"
#include "qbitmap.h"
-#include "qcolormap.h"
#include "qimage.h"
#include "qmatrix.h"
#include "qapplication.h"
XSetForeground(qt_x11Data->display, gc, fillColor.rgba());
} else {
XSetForeground(qt_x11Data->display, gc,
- QColormap::instance(xinfo.screen()).pixel(fillColor));
+ QX11Data::XColorPixel(xinfo.screen(), fillColor));
}
XFillRectangle(qt_x11Data->display, hd, gc, 0, 0, width(), height());
XFreeGC(qt_x11Data->display, gc);
#include "qvariant.h"
#include "qwidget.h"
#include "qdnd_p.h"
-#include "qcolormap.h"
#include "qdebug.h"
#include "qstylesheetstyle_p.h"
#include "qstyle_p.h"
\o -geometry \e geometry, sets the client geometry of the first window
that is shown.
\o -title \e title, sets the application title.
- \o -visual \c TrueColor, forces the application to use a TrueColor
- visual on an 8-bit display.
- \o -ncols \e count, limits the number of colors allocated in the color
- cube on an 8-bit display, if the application is using the
- QApplication::ManyColor color specification. If \e count is 216
- then a 6x6x6 color cube is used (i.e. 6 levels of red, 6 of green,
- and 6 of blue); for other values, a cube approximately proportional
- to a 2x3x1 cube is used.
- \o -cmap, causes the application to install a private color map on an
- 8-bit display.
\endlist
\section1 X11 Notes
void QApplicationPrivate::setSystemPalette(const QPalette &pal)
{
- QPalette adjusted;
-
-#if 0
- // adjust the system palette to avoid dithering
- QColormap cmap = QColormap::instance();
- if (cmap.depths() > 4 && cmap.depths() < 24) {
- for (int g = 0; g < QPalette::NColorGroups; g++)
- for (int i = 0; i < QPalette::NColorRoles; i++) {
- QColor color = pal.color((QPalette::ColorGroup)g, (QPalette::ColorRole)i);
- color = cmap.colorAt(cmap.pixel(color));
- adjusted.setColor((QPalette::ColorGroup)g, (QPalette::ColorRole) i, color);
- }
- }
-#else
- adjusted = pal;
-#endif
-
if (!sys_pal)
- sys_pal = new QPalette(adjusted);
+ sys_pal = new QPalette(pal);
else
- *sys_pal = adjusted;
+ *sys_pal = pal;
if (!QApplicationPrivate::set_pal)
****************************************************************************/
#include "qplatformdefs.h"
-#include "qcolormap.h"
#include "qdesktopwidget.h"
#include "qapplication.h"
#include "qapplication_p.h"
qt_x11Data->ignore_badwindow = false;
qt_x11Data->seen_badwindow = false;
- // colormap control
- qt_x11Data->visual_class = -1;
- qt_x11Data->visual_id = -1;
- qt_x11Data->color_count = 0;
- qt_x11Data->custom_cmap = false;
-
// outside visual/colormap
qt_x11Data->visual = reinterpret_cast<Visual *>(visual);
qt_x11Data->colormap = colormap;
} else if (arg == "-geometry") {
if (++i < argc)
mwGeometry = argv[i];
- } else if (arg == "-ncols") { // xv and netscape use this name
- if (++i < argc)
- qt_x11Data->color_count = qMax(0,atoi(argv[i]));
- } else if (arg == "-visual") { // xv and netscape use this name
- if (++i < argc && !qt_x11Data->visual) {
- QString s = QString::fromLocal8Bit(argv[i]).toLower();
- if (s == QLatin1String("staticgray"))
- qt_x11Data->visual_class = StaticGray;
- else if (s == QLatin1String("grayscale"))
- qt_x11Data->visual_class = XGrayScale;
- else if (s == QLatin1String("staticcolor"))
- qt_x11Data->visual_class = StaticColor;
- else if (s == QLatin1String("pseudocolor"))
- qt_x11Data->visual_class = PseudoColor;
- else if (s == QLatin1String("truecolor"))
- qt_x11Data->visual_class = TrueColor;
- else if (s == QLatin1String("directcolor"))
- qt_x11Data->visual_class = DirectColor;
- else
- qt_x11Data->visual_id = static_cast<int>(strtol(argv[i], 0, 0));
- }
- } else if (arg == "-cmap") { // xv uses this name
- if (!qt_x11Data->colormap)
- qt_x11Data->custom_cmap = true;
}
else if (arg == "-sync")
appSync = !appSync;
QX11InfoData *screen = qt_x11Data->screens + s;
screen->ref = 1; // ensures it doesn't get deleted
screen->screen = s;
+ screen->depth = DefaultDepth(qt_x11Data->display, s);
+ screen->colormap = DefaultColormap(qt_x11Data->display, s);
+ screen->defaultColormap = true;
+ screen->visual = DefaultVisual(qt_x11Data->display, s);
+ screen->defaultVisual = true;
+ screen->cells = screen->visual->map_entries;
int widthMM = DisplayWidthMM(qt_x11Data->display, s);
if (widthMM != 0) {
} else {
screen->dpiY = 72;
}
-
- qt_x11Data->argbVisuals[s] = 0;
- qt_x11Data->argbColormaps[s] = 0;
}
-
#ifndef QT_NO_XRENDER
int xrender_eventbase, xrender_errorbase;
// See if XRender is supported on the connected display
}
#endif
- QColormap::initialize();
+#ifndef QT_NO_XRENDER
+ if (qt_x11Data->use_xrender) {
+ for (int s = 0; s < qt_x11Data->screenCount; s++) {
+ qt_x11Data->argbVisuals[s] = 0;
+ qt_x11Data->argbColormaps[s] = 0;
+
+ Visual *argbVisual = nullptr;
+
+ int nvi = 0;
+ XVisualInfo templ;
+ templ.screen = s;
+ templ.depth = 32;
+ templ.c_class = TrueColor;
+ XVisualInfo *xvi = XGetVisualInfo(
+ qt_x11Data->display,
+ VisualScreenMask | VisualDepthMask | VisualClassMask,
+ &templ, &nvi
+ );
+ for (int idx = 0; idx < nvi; ++idx) {
+ XRenderPictFormat *format = XRenderFindVisualFormat(qt_x11Data->display,
+ xvi[idx].visual);
+ if (format->type == PictTypeDirect && format->direct.alphaMask) {
+ argbVisual = xvi[idx].visual;
+ break;
+ }
+ }
+ XFree(xvi);
+
+ if (argbVisual) {
+ qt_x11Data->argbVisuals[s] = argbVisual;
+ qt_x11Data->argbColormaps[s] = XCreateColormap(
+ qt_x11Data->display,
+ RootWindow(qt_x11Data->display, s),
+ argbVisual, AllocNone
+ );
+ }
+ }
+ }
+#endif
// Support protocols
#ifndef QT_NO_DRAGANDDROP
#ifndef QT_NO_CURSOR
QCursorData::cleanup();
#endif // QT_NO_CURSOR
- QColormap::cleanup();
#ifndef QT_NO_XRENDER
for (int i = 0; i < qt_x11Data->solid_fill_count; ++i) {
bool QApplication::isEffectEnabled(Qt::UIEffect effect)
{
- if (QColormap::instance().depth() < 16 || !QApplicationPrivate::animate_ui)
+ if (!QApplicationPrivate::animate_ui)
return false;
switch(effect) {
#include "qdrawhelper_p.h"
#include "qt_x11_p.h"
#include "qx11info_x11.h"
+#include "qdebug.h"
QT_BEGIN_NAMESPACE
}
}
+uint QX11Data::XColorPixel(const int screen, const QColor &color)
+{
+ Display* x11display = QX11Info::display();
+ if (!x11display) {
+ // qWarning("QX11Data::XColorPixel: no display");
+ return 0;
+ }
+
+ Qt::HANDLE x11colormap = QX11Info::appColormap(screen);
+ if (!x11colormap) {
+ // qWarning("QX11Data::XColorPixel: no color map");
+ return 0;
+ }
+
+ int qr = 0;
+ int qg = 0;
+ int qb = 0;
+ color.getRgb(
+ &qr,
+ &qg,
+ &qb
+ );
+
+ XColor x11color;
+ ::memset(&x11color, 0, sizeof(XColor));
+ x11color.flags = DoRed | DoGreen | DoBlue;
+ x11color.red = qr << 8;
+ x11color.green = qg << 8;
+ x11color.blue = qb << 8;
+
+ XAllocColor(x11display, x11colormap, &x11color);
+
+ // qDebug() << Q_FUNC_INFO << color << x11color.pixel;
+ return x11color.pixel;
+}
+
QT_END_NAMESPACE
bool ignore_badwindow;
bool seen_badwindow;
- // options
- int visual_class;
- int visual_id;
- int color_count;
- bool custom_cmap;
-
// outside visual/colormap
Visual *visual;
Colormap colormap;
static void copyQImageToXImage(const QImage &image, XImage *ximage);
static void copyXImageToQImage(XImage *ximage, QImage &image);
+ static uint XColorPixel(const int screen, const QColor &color);
+
bool has_fontconfig;
int fc_hint_style;
#include "qelapsedtimer.h"
#include "qcursor.h"
#include "qstack.h"
-#include "qcolormap.h"
#include "qdebug.h"
#include "qmenu.h"
#include "qmenu_p.h"
&& q->testAttribute(Qt::WA_TranslucentBackground)
&& !(q->parent()))
XSetWindowBackground(qt_x11Data->display, q->internalWinId(),
- QColormap::instance(xinfo.screen()).pixel(Qt::transparent));
+ QX11Data::XColorPixel(xinfo.screen(), Qt::transparent));
else
XSetWindowBackgroundPixmap(qt_x11Data->display, q->internalWinId(), XNone);
}
else if (brush.style() == Qt::SolidPattern && brush.isOpaque())
XSetWindowBackground(qt_x11Data->display, q->internalWinId(),
- QColormap::instance(xinfo.screen()).pixel(brush.color()));
+ QX11Data::XColorPixel(xinfo.screen(), brush.color()));
else if (isBackgroundInherited())
XSetWindowBackgroundPixmap(qt_x11Data->display, q->internalWinId(), ParentRelative);
else if (brush.style() == Qt::TexturePattern) {
XSetWindowBackgroundPixmap(qt_x11Data->display, q->internalWinId(), bgpixmap.handle());
} else
XSetWindowBackground(qt_x11Data->display, q->internalWinId(),
- QColormap::instance(xinfo.screen()).pixel(brush.color()));
+ QX11Data::XColorPixel(xinfo.screen(), brush.color()));
}
#ifndef QT_NO_CURSOR
of the provided QRgb, and the qGray() function calculates and
return a gray value based on the given value.
- QColor is platform and device independent. The QColormap class
- maps the color to the hardware.
-
For more information about painting in general, see the \l{Paint
System} documentation.
QT_BEGIN_NAMESPACE
-
-class QColormap;
class QVariant;
class Q_GUI_EXPORT QColor
} ahsv;
} ct;
- friend class QColormap;
#ifndef QT_NO_DATASTREAM
friend Q_GUI_EXPORT QDataStream &operator<<(QDataStream &, const QColor &);
friend Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &);
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtGui module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QCOLORMAP_H
-#define QCOLORMAP_H
-
-#include <QtCore/qvector.h>
-
-
-QT_BEGIN_NAMESPACE
-
-class QColor;
-class QColormapPrivate;
-
-class Q_GUI_EXPORT QColormap
-{
-public:
- enum Mode { Direct, Indexed, Gray };
-
- static void initialize();
- static void cleanup();
-
- static QColormap instance(int screen = -1);
-
- QColormap(const QColormap &colormap);
- ~QColormap();
-
- QColormap &operator=(const QColormap &colormap);
-
- Mode mode() const;
-
- int depth() const;
- int size() const;
-
- uint pixel(const QColor &color) const;
- const QColor colorAt(uint pixel) const;
-
- const QVector<QColor> colormap() const;
-
-private:
- QColormap();
- QColormapPrivate *d;
-};
-
-QT_END_NAMESPACE
-
-
-#endif // QCOLORMAP_H
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the documentation of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** GNU Free Documentation License Usage
-** This file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: http://www.gnu.org/copyleft/fdl.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-/*!
- \class QColormap
- \ingroup painting
-
- \brief The QColormap class maps device independent QColors to device
- dependent pixel values.
-*/
-
-/*! \enum QColormap::Mode
-
- This enum describes how QColormap maps device independent RGB
- values to device dependent pixel values.
-
- \value Direct Pixel values are derived directly from the RGB
- values, also known as "True Color."
-
- \value Indexed Pixel values represent indexes into a vector of
- available colors, i.e. QColormap uses the index of the color that
- most closely matches an RGB value.
-
- \value Gray Similar to \c Indexed, pixel values represent a vector
- of available gray tones. QColormap uses the index of the gray
- tone that most closely matches the computed gray tone of an RGB
- value.
-*/
-
-/*!
- \fn QColormap QColormap::instance(int screen)
-
- Returns the colormap for the specified \a screen. If \a screen is
- -1, this function returns the colormap for the default screen.
-*/
-
-/*!
- \fn QColormap::QColormap(const QColormap &colormap)
-
- Constructs a copy of another \a colormap.
-*/
-
-/*!
- \fn QColormap::~QColormap()
-
- Destroys the colormap.
-*/
-
-/*!
- \fn int QColormap::size() const
-
- Returns the size of the colormap for \c Indexed and \c Gray modes;
- Returns -1 for \c Direct mode.
-
- \sa colormap()
-*/
-
-/*!
- \fn uint QColormap::pixel(const QColor &color) const
-
- Returns a device dependent pixel value for the \a color.
-
- \sa colorAt()
-*/
-
-/*!
- \fn int QColormap::depth() const
-
- Returns the depth of the device.
-
- \sa size()
-*/
-
-/*!
- \fn QColormap::Mode QColormap::mode() const
-
- Returns the mode of this colormap.
-
- \sa QColormap::Mode
-*/
-
-/*!
- \fn const QColor QColormap::colorAt(uint pixel) const
-
- Returns a QColor for the \a pixel.
-
- \sa pixel()
-*/
-
-/*!
- \fn const QVector<QColor> QColormap::colormap() const
-
- Returns a vector of colors which represents the devices colormap
- for \c Indexed and \c Gray modes. This function returns an empty
- vector for \c Direct mode.
-
- \sa size()
-*/
-
-/*! \fn HPALETTE QColormap::hPal()
-
- This function is only available on Windows.
-
- Returns an handle to the HPALETTE used by this colormap. If no
- HPALETTE is being used, this function returns zero.
-*/
-
-/*! \since 4.2
-
- \fn QColormap &QColormap::operator=(const QColormap &colormap)
-
- Assigns the given \a colormap to \e this color map and returns
- a reference to \e this color map.
-*/
-
-/*!
- \fn void QColormap::initialize()
- \internal
-*/
-
-/*!
- \fn void QColormap::cleanup()
- \internal
-*/
+++ /dev/null
-/****************************************************************************
-**
-** Copyright (C) 2015 The Qt Company Ltd.
-** Copyright (C) 2016 Ivailo Monev
-**
-** This file is part of the QtGui module of the Katie Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-**
-** GNU Lesser General Public License Usage
-** This file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qcolormap.h"
-
-#include "qapplication.h"
-#include "qdebug.h"
-#include "qdesktopwidget.h"
-#include "qvector.h"
-#include "qx11info_x11.h"
-#include "qt_x11_p.h"
-#include "qguicommon_p.h"
-#include "qcorecommon_p.h"
-
-#include <limits.h>
-
-QT_BEGIN_NAMESPACE
-
-class QColormapPrivate
-{
-public:
- QColormapPrivate()
- : ref(1), mode(QColormap::Direct), depth(0),
- colormap(0), defaultColormap(true),
- visual(nullptr), defaultVisual(true),
- r_max(0), g_max(0), b_max(0),
- r_shift(0), g_shift(0), b_shift(0)
- {}
-
- QAtomicInt ref;
-
- QColormap::Mode mode;
- int depth;
-
- Colormap colormap;
- bool defaultColormap;
-
- Visual *visual;
- bool defaultVisual;
-
- int r_max;
- int g_max;
- int b_max;
-
- uint r_shift;
- uint g_shift;
- uint b_shift;
-
- QVector<QColor> colors;
- QVector<int> pixels;
-};
-
-
-static uint right_align(uint v)
-{
- while (!(v & 0x1))
- v >>= 1;
- return v;
-}
-
-static int cube_root(int v)
-{
- if (v == 1)
- return 1;
- // brute force algorithm
- int i = 1;
- for (;;) {
- const int b = i * i * i;
- if (b <= v) {
- ++i;
- } else {
- --i;
- break;
- }
- }
- return i;
-}
-
-static Visual *find_visual(Display *display,
- int screen,
- int visual_class,
- int visual_id,
- int *depth,
- bool *defaultVisual)
-{
- XVisualInfo *vi, rvi;
- int count;
-
- uint mask = VisualScreenMask;
- rvi.screen = screen;
-
- if (visual_class != -1) {
- rvi.c_class = visual_class;
- mask |= VisualClassMask;
- }
- if (visual_id != -1) {
- rvi.visualid = visual_id;
- mask |= VisualIDMask;
- }
-
- Visual *visual = DefaultVisual(display, screen);
- *defaultVisual = true;
- *depth = DefaultDepth(display, screen);
-
- vi = XGetVisualInfo(display, mask, &rvi, &count);
- if (vi) {
- int best = 0;
- for (int x = 0; x < count; ++x) {
- if (vi[x].depth > vi[best].depth)
- best = x;
- }
- if (best >= 0 && best <= count && vi[best].visualid != XVisualIDFromVisual(visual)) {
- visual = vi[best].visual;
- *defaultVisual = (visual == DefaultVisual(display, screen));
- *depth = vi[best].depth;
- }
- }
- if (vi)
- XFree((char *)vi);
- return visual;
-}
-
-static void query_colormap(QColormapPrivate *d, int screen)
-{
- Display *display = QX11Info::display();
-
- // query existing colormap
- int q_colors = (((1u << d->depth) > 256u) ? 256u : (1u << d->depth));
- QSTACKARRAY(XColor, queried, 256);
- for (int x = 0; x < q_colors; ++x)
- queried[x].pixel = x;
- XQueryColors(display, d->colormap, queried, q_colors);
-
- d->colors.resize(q_colors);
- for (int x = 0; x < q_colors; ++x) {
- if (queried[x].red == 0
- && queried[x].green == 0
- && queried[x].blue == 0
- && queried[x].pixel != BlackPixel(display, screen)) {
- // unallocated color cell, skip it
- continue;
- }
-
- d->colors[x] = QColor::fromRgbF(queried[x].red / float(USHRT_MAX),
- queried[x].green / float(USHRT_MAX),
- queried[x].blue / float(USHRT_MAX));
- }
-
- // for missing colors, find the closest color in the existing colormap
- Q_ASSERT(d->pixels.size());
- for (int x = 0; x < d->pixels.size(); ++x) {
- if (d->pixels.at(x) != -1)
- continue;
-
- QRgb rgb;
- if (d->mode == QColormap::Indexed) {
- const int r = (x / (d->g_max * d->b_max)) % d->r_max;
- const int g = (x / d->b_max) % d->g_max;
- const int b = x % d->b_max;
- rgb = qRgb((r * 0xff + (d->r_max - 1) / 2) / (d->r_max - 1),
- (g * 0xff + (d->g_max - 1) / 2) / (d->g_max - 1),
- (b * 0xff + (d->b_max - 1) / 2) / (d->b_max - 1));
- } else {
- rgb = qRgb(x, x, x);
- }
-
- // find closest color
- int mindist = INT_MAX, best = -1;
- for (int y = 0; y < q_colors; ++y) {
- int r = qRed(rgb) - (queried[y].red >> 8);
- int g = qGreen(rgb) - (queried[y].green >> 8);
- int b = qBlue(rgb) - (queried[y].blue >> 8);
- int dist = (r * r) + (g * g) + (b * b);
- if (dist < mindist) {
- mindist = dist;
- best = y;
- }
- }
-
- Q_ASSERT(best >= 0 && best < q_colors);
- if (d->visual->c_class & 1) {
- XColor xcolor;
- xcolor.red = queried[best].red;
- xcolor.green = queried[best].green;
- xcolor.blue = queried[best].blue;
- xcolor.pixel = queried[best].pixel;
-
- if (XAllocColor(display, d->colormap, &xcolor)) {
- d->pixels[x] = xcolor.pixel;
- } else {
- // some weird stuff is going on...
- d->pixels[x] = (qGray(rgb) < 127
- ? BlackPixel(display, screen)
- : WhitePixel(display, screen));
- }
- } else {
- d->pixels[x] = best;
- }
- }
-}
-
-static void init_gray(QColormapPrivate *d, int screen)
-{
- d->pixels.resize(d->r_max);
-
- for (int g = 0; g < d->g_max; ++g) {
- const int gray = (g * 0xff + (d->r_max - 1) / 2) / (d->r_max - 1);
-
- d->pixels[g] = -1;
-
- if (d->visual->c_class & 1) {
- XColor xcolor;
- xcolor.red = gray * 0x101;
- xcolor.green = gray * 0x101;
- xcolor.blue = gray * 0x101;
- xcolor.pixel = 0ul;
-
- if (XAllocColor(QX11Info::display(), d->colormap, &xcolor))
- d->pixels[g] = xcolor.pixel;
- }
- }
-
- query_colormap(d, screen);
-}
-
-static void init_indexed(QColormapPrivate *d, int screen)
-{
- d->pixels.resize(d->r_max * d->g_max * d->b_max);
-
- // create color cube
- for (int x = 0, r = 0; r < d->r_max; ++r) {
- for (int g = 0; g < d->g_max; ++g) {
- for (int b = 0; b < d->b_max; ++b, ++x) {
- const QRgb rgb = qRgb((r * 0xff + (d->r_max - 1) / 2) / (d->r_max - 1),
- (g * 0xff + (d->g_max - 1) / 2) / (d->g_max - 1),
- (b * 0xff + (d->b_max - 1) / 2) / (d->b_max - 1));
-
- d->pixels[x] = -1;
-
- if (d->visual->c_class & 1) {
- XColor xcolor;
- xcolor.red = qRed(rgb) * 0x101;
- xcolor.green = qGreen(rgb) * 0x101;
- xcolor.blue = qBlue(rgb) * 0x101;
- xcolor.pixel = 0ul;
-
- if (XAllocColor(QX11Info::display(), d->colormap, &xcolor))
- d->pixels[x] = xcolor.pixel;
- }
- }
- }
- }
-
- query_colormap(d, screen);
-}
-
-static void init_direct(QColormapPrivate *d)
-{
- if (d->visual->c_class != DirectColor)
- return;
-
- QVector<XColor> colorTable(d->r_max + d->g_max + d->b_max);
- int i = 0;
-
- for (int r = 0; r < d->r_max; ++r) {
- colorTable[i].red = r << 8 | r;
- colorTable[i].green = 0;
- colorTable[i].blue = 0;
- colorTable[i].pixel = r << d->r_shift;
- colorTable[i].flags = DoRed;
- ++i;
- }
-
- for (int g = 0; g < d->g_max; ++g) {
- colorTable[i].red = 0;
- colorTable[i].green = g << 8 | g;
- colorTable[i].blue = 0;
- colorTable[i].pixel = g << d->g_shift;
- colorTable[i].flags = DoGreen;
- ++i;
- }
-
- for (int b = 0; b < d->b_max; ++b) {
- colorTable[i].red = 0;
- colorTable[i].green = 0;
- colorTable[i].blue = (b << 8 | b);
- colorTable[i].pixel = b << d->b_shift;
- colorTable[i].flags = DoBlue;
- ++i;
- }
-
- XStoreColors(qt_x11Data->display, d->colormap, colorTable.data(), colorTable.count());
-}
-
-static QColormap **cmaps = nullptr;
-
-void QColormap::initialize()
-{
- Display *display = QX11Info::display();
- const int screens = ScreenCount(display);
-
- cmaps = new QColormap*[screens];
-
- for (int i = 0; i < screens; ++i) {
- cmaps[i] = new QColormap;
- QColormapPrivate * const d = cmaps[i]->d;
-
- bool use_stdcmap = false;
- int color_count = qt_x11Data->color_count;
-
- // defaults
- d->depth = DefaultDepth(display, i);
- d->colormap = DefaultColormap(display, i);
- d->defaultColormap = true;
- d->visual = DefaultVisual(display, i);
- d->defaultVisual = true;
-
- Visual *argbVisual = nullptr;
-
- if (qt_x11Data->visual && i == DefaultScreen(display)) {
- // only use the outside colormap on the default screen
- d->visual = find_visual(display, i, qt_x11Data->visual->c_class,
- XVisualIDFromVisual(qt_x11Data->visual),
- &d->depth, &d->defaultVisual);
- } else if ((qt_x11Data->visual_class != -1 && qt_x11Data->visual_class >= 0 && qt_x11Data->visual_class < 6)
- || (qt_x11Data->visual_id != -1)) {
- // look for a specific visual or type of visual
- d->visual = find_visual(display, i, qt_x11Data->visual_class, qt_x11Data->visual_id,
- &d->depth, &d->defaultVisual);
- } else if (!qt_x11Data->custom_cmap) {
- XStandardColormap *stdcmap = nullptr;
- int ncmaps = 0;
-
-#ifndef QT_NO_XRENDER
- if (qt_x11Data->use_xrender) {
- int nvi;
- XVisualInfo templ;
- templ.screen = i;
- templ.depth = 32;
- templ.c_class = TrueColor;
- XVisualInfo *xvi = XGetVisualInfo(qt_x11Data->display, VisualScreenMask |
- VisualDepthMask |
- VisualClassMask, &templ, &nvi);
- for (int idx = 0; idx < nvi; ++idx) {
- XRenderPictFormat *format = XRenderFindVisualFormat(qt_x11Data->display,
- xvi[idx].visual);
- if (format->type == PictTypeDirect && format->direct.alphaMask) {
- argbVisual = xvi[idx].visual;
- break;
- }
- }
- XFree(xvi);
- }
-#endif
- if (XGetRGBColormaps(display, RootWindow(display, i),
- &stdcmap, &ncmaps, XA_RGB_DEFAULT_MAP)) {
- if (stdcmap) {
- for (int c = 0; c < ncmaps; ++c) {
- if (!stdcmap[c].red_max ||
- !stdcmap[c].green_max ||
- !stdcmap[c].blue_max ||
- !stdcmap[c].red_mult ||
- !stdcmap[c].green_mult ||
- !stdcmap[c].blue_mult)
- continue; // invalid stdcmap
-
- XVisualInfo proto;
- proto.visualid = stdcmap[c].visualid;
- proto.screen = i;
-
- int nvisuals = 0;
- XVisualInfo *vi = XGetVisualInfo(display, VisualIDMask | VisualScreenMask,
- &proto, &nvisuals);
- if (vi) {
- if (nvisuals > 0) {
- use_stdcmap = true;
-
- d->mode = ((vi[0].visual->c_class < StaticColor)
- ? Gray
- : ((vi[0].visual->c_class < TrueColor)
- ? Indexed
- : Direct));
-
- d->depth = vi[0].depth;
- d->colormap = stdcmap[c].colormap;
- d->defaultColormap = true;
- d->visual = vi[0].visual;
- d->defaultVisual = (d->visual == DefaultVisual(display, i));
-
- d->r_max = stdcmap[c].red_max + 1;
- d->g_max = stdcmap[c].green_max + 1;
- d->b_max = stdcmap[c].blue_max + 1;
-
- if (d->mode == Direct) {
- // calculate offsets
- d->r_shift = lowest_bit(d->visual->red_mask);
- d->g_shift = lowest_bit(d->visual->green_mask);
- d->b_shift = lowest_bit(d->visual->blue_mask);
- } else {
- d->r_shift = 0;
- d->g_shift = 0;
- d->b_shift = 0;
- }
- }
- XFree(vi);
- }
- break;
- }
- XFree(stdcmap);
- }
- }
- }
- if (!use_stdcmap) {
- switch (d->visual->c_class) {
- case StaticGray:
- d->mode = Gray;
-
- d->r_max = d->g_max = d->b_max = d->visual->map_entries;
- break;
-
- case XGrayScale:
- d->mode = Gray;
-
- // follow precedent set in libXmu...
- if (color_count != 0)
- d->r_max = d->g_max = d->b_max = color_count;
- else if (d->visual->map_entries > 65000)
- d->r_max = d->g_max = d->b_max = 4096;
- else if (d->visual->map_entries > 4000)
- d->r_max = d->g_max = d->b_max = 512;
- else if (d->visual->map_entries > 250)
- d->r_max = d->g_max = d->b_max = 12;
- else
- d->r_max = d->g_max = d->b_max = 4;
- break;
-
- case StaticColor:
- d->mode = Indexed;
-
- d->r_max = right_align(d->visual->red_mask) + 1;
- d->g_max = right_align(d->visual->green_mask) + 1;
- d->b_max = right_align(d->visual->blue_mask) + 1;
- break;
-
- case PseudoColor:
- d->mode = Indexed;
-
- // follow precedent set in libXmu...
- if (color_count != 0)
- d->r_max = d->g_max = d->b_max = cube_root(color_count);
- else if (d->visual->map_entries > 65000)
- d->r_max = d->g_max = d->b_max = 27;
- else if (d->visual->map_entries > 4000)
- d->r_max = d->g_max = d->b_max = 12;
- else if (d->visual->map_entries > 250)
- d->r_max = d->g_max = d->b_max = cube_root(d->visual->map_entries - 125);
- else
- d->r_max = d->g_max = d->b_max = cube_root(d->visual->map_entries);
- break;
-
- case TrueColor:
- case DirectColor:
- d->mode = Direct;
-
- d->r_max = right_align(d->visual->red_mask) + 1;
- d->g_max = right_align(d->visual->green_mask) + 1;
- d->b_max = right_align(d->visual->blue_mask) + 1;
-
- d->r_shift = lowest_bit(d->visual->red_mask);
- d->g_shift = lowest_bit(d->visual->green_mask);
- d->b_shift = lowest_bit(d->visual->blue_mask);
- break;
- }
- }
-
- bool ownColormap = false;
- if (qt_x11Data->colormap && i == DefaultScreen(display)) {
- // only use the outside colormap on the default screen
- d->colormap = qt_x11Data->colormap;
- d->defaultColormap = (d->colormap == DefaultColormap(display, i));
- } else if ((!use_stdcmap
- && (((d->visual->c_class & 1) && qt_x11Data->custom_cmap)
- || d->visual != DefaultVisual(display, i)))
- || d->visual->c_class == DirectColor) {
- // allocate custom colormap (we always do this when using DirectColor visuals)
- d->colormap =
- XCreateColormap(display, RootWindow(display, i), d->visual,
- d->visual->c_class == DirectColor ? AllocAll : AllocNone);
- d->defaultColormap = false;
- ownColormap = true;
- }
-
- switch (d->mode) {
- case Gray:
- init_gray(d, i);
- break;
- case Indexed:
- init_indexed(d, i);
- break;
- case Direct:
- if (ownColormap)
- init_direct(d);
- break;
- }
-
- QX11InfoData *screen = qt_x11Data->screens + i;
- screen->depth = d->depth;
- screen->visual = d->visual;
- screen->defaultVisual = d->defaultVisual;
- screen->colormap = d->colormap;
- screen->defaultColormap = d->defaultColormap;
- screen->cells = screen->visual->map_entries;
-
- if (argbVisual) {
- qt_x11Data->argbVisuals[i] = argbVisual;
- qt_x11Data->argbColormaps[i] = XCreateColormap(display, RootWindow(display, i), argbVisual, AllocNone);
- }
-
- // ###
- // We assume that 8bpp == pseudocolor, but this is not
- // always the case (according to the X server), so we need
- // to make sure that our internal data is setup in a way
- // that is compatible with our assumptions
- if (screen->visual->c_class == TrueColor && screen->depth == 8 && screen->cells == 8)
- screen->cells = 256;
- }
-}
-
-void QColormap::cleanup()
-{
- Display *display = QX11Info::display();
- const int screens = ScreenCount(display);
-
- for (int i = 0; i < screens; ++i)
- delete cmaps[i];
-
- delete [] cmaps;
- cmaps = nullptr;
-}
-
-
-QColormap QColormap::instance(int screen)
-{
- if (screen == -1)
- screen = QX11Info::appScreen();
- return *cmaps[screen];
-}
-
-/*! \internal
- Constructs a new colormap.
-*/
-QColormap::QColormap()
- : d(new QColormapPrivate)
-{
-}
-
-QColormap::QColormap(const QColormap &colormap)
- : d(colormap.d)
-{
- d->ref.ref();
-}
-
-QColormap::~QColormap()
-{
- if (!d->ref.deref()) {
- if (!d->defaultColormap)
- XFreeColormap(QX11Info::display(), d->colormap);
- delete d;
- }
-}
-
-QColormap::Mode QColormap::mode() const
-{
- return d->mode;
-}
-
-int QColormap::depth() const
-{
- return d->depth;
-}
-
-int QColormap::size() const
-{
- switch (d->mode) {
- case Gray:
- return d->r_max;
- case Indexed:
- return d->r_max * d->g_max * d->b_max;
- case Direct:
- return -1;
- }
- Q_UNREACHABLE();
-}
-
-uint QColormap::pixel(const QColor &color) const
-{
- const QColor c = color.toRgb();
- const uint r = (c.ct.argb.red * d->r_max) >> 16;
- const uint g = (c.ct.argb.green * d->g_max) >> 16;
- const uint b = (c.ct.argb.blue * d->b_max) >> 16;
-
- switch (d->mode) {
- case Gray:
- return d->pixels.at((r * 30 + g * 59 + b * 11) / 100);
- case Indexed:
- return d->pixels.at(r * d->g_max * d->b_max + g * d->b_max + b);
- case Direct:
- return (r << d->r_shift) + (g << d->g_shift) + (b << d->b_shift);
- }
- Q_UNREACHABLE();
-}
-
-const QColor QColormap::colorAt(uint pixel) const
-{
- if (d->mode != Direct) {
- Q_ASSERT(pixel <= (uint)d->colors.size());
- return d->colors.at(pixel);
- }
-
- const int r = (((pixel & d->visual->red_mask) >> d->r_shift) << 8) / d->r_max;
- const int g = (((pixel & d->visual->green_mask) >> d->g_shift) << 8) / d->g_max;
- const int b = (((pixel & d->visual->blue_mask) >> d->b_shift) << 8) / d->b_max;
- return QColor(r, g, b);
-}
-
-const QVector<QColor> QColormap::colormap() const
-{
- return d->colors;
-}
-
-QColormap &QColormap::operator=(const QColormap &colormap)
-{
- qAtomicAssign(d, colormap.d);
- return *this;
-}
-
-QT_END_NAMESPACE
#include "qpainterpath_p.h"
#include "qpen.h"
#include "qcolor.h"
-#include "qcolormap.h"
#include "qstylehelper_p.h"
#include "qpaintengine_p.h"
#include "qpaintengine_x11_p.h"
vals.foreground = pen.color().rgba();
vals.background = qt_transparentrgba;
} else {
- QColormap cmap = QColormap::instance(d->scrn);
- vals.foreground = cmap.pixel(pen.color());
- vals.background = cmap.pixel(QColor(Qt::transparent));
+ vals.foreground = QX11Data::XColorPixel(d->scrn, pen.color());
+ vals.background = QX11Data::XColorPixel(d->scrn, QColor(Qt::transparent));
}
vals.foreground = d->cbrush.color().rgba();
vals.background = qt_transparentrgba;
} else {
- QColormap cmap = QColormap::instance(d->scrn);
- vals.foreground = cmap.pixel(d->cbrush.color());
- vals.background = cmap.pixel(QColor(Qt::transparent));
+ vals.foreground = QX11Data::XColorPixel(d->scrn, d->cbrush.color());
+ vals.background = QX11Data::XColorPixel(d->scrn, QColor(Qt::transparent));
if (!qt_x11Data->use_xrender && d->has_brush && !d->has_pattern && !brush.isOpaque()) {
QPixmap pattern = qt_patternForAlpha(brush.color().alpha(), d->scrn);
if (mono_dst) {
XSetForeground(d->dpy, d->gc, qGray(d->cpen.color().rgb()) > 127 ? 0 : 1);
} else {
- QColormap cmap = QColormap::instance(d->scrn);
- XSetForeground(d->dpy, d->gc, cmap.pixel(d->cpen.color()));
+ XSetForeground(d->dpy, d->gc, QX11Data::XColorPixel(d->scrn, d->cpen.color()));
}
XFillRectangle(d->dpy, d->hd, d->gc, x, y, sw, sh);
restore_clip = true;
{ QLatin1String("QCloseEvent"), QLatin1String("QtGui/qevent.h") },
{ QLatin1String("QColor"), QLatin1String("QtGui/qcolor.h") },
{ QLatin1String("QColorDialog"), QLatin1String("QtGui/qcolordialog.h") },
- { QLatin1String("QColormap"), QLatin1String("QtGui/qcolormap.h") },
{ QLatin1String("QColumnView"), QLatin1String("QtGui/qcolumnview.h") },
{ QLatin1String("QComboBox"), QLatin1String("QtGui/qcombobox.h") },
{ QLatin1String("QCommandLinkButton"), QLatin1String("QtGui/qcommandlinkbutton.h") },