mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-24 02:42:48 +00:00
kdeui: obtain color names via QColor::colorNames()
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
3b19a3c320
commit
84b55ff800
2 changed files with 7 additions and 134 deletions
|
@ -543,7 +543,6 @@ public:
|
||||||
void slotColorCellDoubleClicked(int index , const QColor&);
|
void slotColorCellDoubleClicked(int index , const QColor&);
|
||||||
void slotColorTextSelected(const QString &colorText);
|
void slotColorTextSelected(const QString &colorText);
|
||||||
void slotSetColors(const QString &_collectionName);
|
void slotSetColors(const QString &_collectionName);
|
||||||
void slotShowNamedColorReadError(void);
|
|
||||||
|
|
||||||
KColorTable *q;
|
KColorTable *q;
|
||||||
QString i18n_namedColors;
|
QString i18n_namedColors;
|
||||||
|
@ -619,43 +618,6 @@ KColorTable::name() const
|
||||||
return d->combo->currentText();
|
return d->combo->currentText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char * const *namedColorFilePath(void)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// 2000-02-05 Espen Sand.
|
|
||||||
// Add missing filepaths here. Make sure the last entry is 0, 0!
|
|
||||||
//
|
|
||||||
// 2009-06-16 Pino Toscano
|
|
||||||
//
|
|
||||||
// You can specify either absolute paths or relative locations
|
|
||||||
// wrt KStandardDirs resources. In either way, there should be two
|
|
||||||
// "strings" for each path.
|
|
||||||
// - absolute path: specify it directly, then add 0 as second item
|
|
||||||
// * example: "/usr/share/X11/rgb.txt", 0,
|
|
||||||
// - KStandardDirs location: specify the filename as first item,
|
|
||||||
// then add the resource as second
|
|
||||||
// * example: "kdeui/rgb.txt", "data",
|
|
||||||
//
|
|
||||||
static const char * const path[] = {
|
|
||||||
#ifdef Q_WS_X11
|
|
||||||
#ifdef X11_RGBFILE
|
|
||||||
X11_RGBFILE, 0,
|
|
||||||
#endif
|
|
||||||
"/usr/share/X11/rgb.txt", 0,
|
|
||||||
"/usr/X11R6/lib/X11/rgb.txt", 0,
|
|
||||||
"/usr/openwin/lib/X11/rgb.txt", 0, // for Solaris.
|
|
||||||
#else /* systems without X11 */
|
|
||||||
"kdeui/rgb.txt", "data",
|
|
||||||
#endif
|
|
||||||
0, 0
|
|
||||||
};
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KColorTable::readNamedColor(void)
|
KColorTable::readNamedColor(void)
|
||||||
{
|
{
|
||||||
|
@ -663,105 +625,17 @@ KColorTable::readNamedColor(void)
|
||||||
return; // Strings already present
|
return; // Strings already present
|
||||||
}
|
}
|
||||||
|
|
||||||
KGlobal::locale()->insertCatalog("kdelibs_colors4");
|
QStringList list;
|
||||||
|
foreach (const QString &colorName, QColor::colorNames()) {
|
||||||
//
|
const QColor color(colorName);
|
||||||
// Code somewhat inspired by KColorCollection.
|
list.append(colorName);
|
||||||
//
|
d->m_namedColorMap[ colorName ] = color;
|
||||||
|
|
||||||
const char * const *path = namedColorFilePath();
|
|
||||||
for (int i = 0; path[i]; i += 2) {
|
|
||||||
QString file;
|
|
||||||
if (path[i + 1]) {
|
|
||||||
file = KStandardDirs::locate(path[i + 1], QString::fromLatin1(path[i]));
|
|
||||||
if (file.isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
file = QString::fromLatin1(path[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
QFile paletteFile(file);
|
|
||||||
if (!paletteFile.open(QIODevice::ReadOnly)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray line;
|
|
||||||
QStringList list;
|
|
||||||
while (!paletteFile.atEnd()) {
|
|
||||||
line = paletteFile.readLine();
|
|
||||||
|
|
||||||
int red, green, blue;
|
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
if (sscanf(line, "%d %d %d%n", &red, &green, &blue, &pos) == 3) {
|
|
||||||
//
|
|
||||||
// Remove duplicates. Every name with a space and every name
|
|
||||||
// that start with "gray".
|
|
||||||
//
|
|
||||||
QString name = line.mid(pos).trimmed();
|
|
||||||
QByteArray s1 = line.mid(pos);
|
|
||||||
if (name.isNull() || name.indexOf(' ') != -1 ||
|
|
||||||
name.indexOf("gray") != -1 || name.indexOf("grey") != -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QColor color(red, green, blue);
|
|
||||||
if (color.isValid()) {
|
|
||||||
const QString colorName(i18nc("color", name.toLatin1().data()));
|
|
||||||
list.append(colorName);
|
|
||||||
d->m_namedColorMap[ colorName ] = color;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
list.sort();
|
|
||||||
d->mNamedColorList->addItems(list);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d->mNamedColorList->count() == 0) {
|
list.sort();
|
||||||
//
|
d->mNamedColorList->addItems(list);
|
||||||
// Give the error dialog box a chance to center above the
|
|
||||||
// widget (or dialog). If we had displayed it now we could get a
|
|
||||||
// situation where the (modal) error dialog box pops up first
|
|
||||||
// preventing the real dialog to become visible until the
|
|
||||||
// error dialog box is removed (== bad UI).
|
|
||||||
//
|
|
||||||
QTimer::singleShot(10, this, SLOT(slotShowNamedColorReadError()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
KColorTable::KColorTablePrivate::slotShowNamedColorReadError(void)
|
|
||||||
{
|
|
||||||
if (mNamedColorList->count() == 0) {
|
|
||||||
QString pathMsg;
|
|
||||||
int pathCount = 0;
|
|
||||||
|
|
||||||
const char * const *path = namedColorFilePath();
|
|
||||||
for (int i = 0; path[i]; i += 2, ++pathCount) {
|
|
||||||
if (path[i + 1]) {
|
|
||||||
pathMsg += QLatin1String(path[i + 1]) + ", " + QString::fromLatin1(path[i]);
|
|
||||||
} else {
|
|
||||||
pathMsg += QLatin1String(path[i]);
|
|
||||||
}
|
|
||||||
pathMsg += '\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
QString finalMsg = i18ncp("%1 is the number of paths, %2 is the list of paths (with newlines between them)",
|
|
||||||
"Unable to read X11 RGB color strings. The following "
|
|
||||||
"file location was examined:\n%2",
|
|
||||||
"Unable to read X11 RGB color strings. The following "
|
|
||||||
"file locations were examined:\n%2",
|
|
||||||
pathCount, pathMsg );
|
|
||||||
|
|
||||||
KMessageBox::sorry(q, finalMsg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 2000-02-12 Espen Sand
|
// 2000-02-12 Espen Sand
|
||||||
// Set the color in two steps. The setColors() slot will not emit a signal
|
// Set the color in two steps. The setColors() slot will not emit a signal
|
||||||
|
|
|
@ -53,7 +53,6 @@ private:
|
||||||
Q_PRIVATE_SLOT(d, void slotColorCellDoubleClicked( int index , const QColor& ))
|
Q_PRIVATE_SLOT(d, void slotColorCellDoubleClicked( int index , const QColor& ))
|
||||||
Q_PRIVATE_SLOT(d, void slotColorTextSelected( const QString &colorText ))
|
Q_PRIVATE_SLOT(d, void slotColorTextSelected( const QString &colorText ))
|
||||||
Q_PRIVATE_SLOT(d, void slotSetColors( const QString &_collectionName ))
|
Q_PRIVATE_SLOT(d, void slotSetColors( const QString &_collectionName ))
|
||||||
Q_PRIVATE_SLOT(d, void slotShowNamedColorReadError( void ))
|
|
||||||
|
|
||||||
void readNamedColor( void );
|
void readNamedColor( void );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue