Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 1c489620 authored by Laurent Montel's avatar Laurent Montel 😁

Avoid to create a qcolor for each lineedit

parent 011440a8
......@@ -170,12 +170,6 @@ void AddresseeLineEditPrivate::searchInBaloo()
doCompletion(mLastSearchMode);
}
void AddresseeLineEditPrivate::alternateColor()
{
const KColorScheme colorScheme(QPalette::Active, KColorScheme::View);
mAlternateColor = colorScheme.background(KColorScheme::AlternateBackground).color();
}
void AddresseeLineEditPrivate::setCompletedItems(const QStringList &items, bool autoSuggest)
{
KCompletionBox *completionBox = q->completionBox();
......@@ -187,11 +181,8 @@ void AddresseeLineEditPrivate::setCompletedItems(const QStringList &items, bool
for (int i = 0; i < numberOfItems; ++i) {
QListWidgetItem *item = new QListWidgetItem(items.at(i), completionBox);
if (!items.at(i).startsWith(s_completionItemIndentString)) {
if (!mAlternateColor.isValid()) {
alternateColor();
}
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
item->setBackgroundColor(mAlternateColor);
item->setBackgroundColor(AddresseeLineEditManager::self()->alternateColor());
}
completionBox->addItem(item);
}
......
......@@ -41,7 +41,6 @@ public:
AddresseeLineEditPrivate(AddresseeLineEdit *qq, bool enableCompletion);
~AddresseeLineEditPrivate();
void loadBalooBlackList();
void alternateColor();
void init();
void setCompletedItems(const QStringList &items, bool autoSuggest);
void addCompletionItem(const QString &string, int weight, int source, const QStringList *keyWords = nullptr);
......@@ -136,7 +135,6 @@ private:
AddresseeLineEdit *q;
QToolButton *mToolButton;
QTimer mDelayedQueryTimer;
QColor mAlternateColor;
QString mPreviousAddresses;
QString mSearchString;
QList<KJob *> mMightBeGroupJobs;
......
......@@ -28,8 +28,10 @@
#include <QCoreApplication>
#include <KConfigGroup>
#include <KSharedConfig>
#include <KColorScheme>
#include <KLDAP/LdapServer>
#include <AkonadiCore/Session>
using namespace KPIM;
Q_GLOBAL_STATIC(AddresseeLineEditManager, sInstance)
......@@ -232,3 +234,13 @@ void AddresseeLineEditManager::setAutoGroupExpand(bool checked)
group.writeEntry("AutoGroupExpand", mAutoGroupExpand);
}
}
QColor AddresseeLineEditManager::alternateColor() const
{
if (!mAlternateColor.isValid()) {
const KColorScheme colorScheme(QPalette::Active, KColorScheme::View);
mAlternateColor = colorScheme.background(KColorScheme::AlternateBackground).color();
}
return mAlternateColor;
}
......@@ -27,6 +27,8 @@
#include <QWeakPointer>
#include <ldap/ldapclientsearch.h>
#include <qstringlist.h>
#include <QColor>
class QTimer;
class QNetworkConfigurationManager;
namespace KPIM {
......@@ -121,9 +123,12 @@ public:
void setShowOU(bool showOU);
bool autoGroupExpand() const;
void setAutoGroupExpand(bool autoGroupExpand);
void setAutoGroupExpand(bool checked);
QColor alternateColor() const;
private:
mutable QColor mAlternateColor;
bool mShowOU;
bool mAutoGroupExpand;
KMailCompletion *mCompletion;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment