Commit 1759154e authored by Laurent Montel's avatar Laurent Montel 😁

Add test application for autogenerate color. And improve color generation.

CCMAIL: sabine@kde.org
parent 72313069
......@@ -119,3 +119,5 @@ target_link_libraries(eventviews
set_target_properties(eventviews PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
install(TARGETS eventviews ${INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES agenda/calendardecoration.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR})
add_subdirectory(tests)
......@@ -946,6 +946,21 @@ void Prefs::setResourceColor ( const QString &cal, const QColor &color )
{
d->mBaseConfig.setResourceColor( cal, color );
}
#define USE_RANDOM
void Prefs::createNewColor(QColor &defColor, int seed)
{
#ifdef USE_RANDOM
Q_UNUSED(seed);
QColor col = QColor(qrand() % 256, qrand() % 256, qrand() % 256);
defColor = col;
#else
int h, s, v;
defColor.getHsv( &h, &s, &v );
h = ( seed % 12 ) * 30;
s -= s * static_cast<int>( ( ( seed / 12 ) % 2 ) * 0.5 );
defColor.setHsv( h, s, v );
#endif
}
QColor Prefs::resourceColor( const QString &cal )
{
......@@ -970,17 +985,12 @@ QColor Prefs::resourceColor( const QString &cal )
if ( seed > 0 && seed - 1 < (int)colors.size() ) {
defColor = QColor( colors[seed-1] );
} else {
int h, s, v;
defColor.getHsv( &h, &s, &v );
h = ( seed % 12 ) * 30;
s -= s * static_cast<int>( ( ( seed / 12 ) % 2 ) * 0.5 );
defColor.setHsv( h, s, v );
createNewColor(defColor, seed);
}
d->setInt( d->mBaseConfig.defaultResourceColorSeedItem(), ( seed + 1 ) );
d->mBaseConfig.setResourceColor( cal, defColor );
color = d->mBaseConfig.mResourceColors[cal];
}
if ( color.isValid() ) {
return color;
} else {
......
......@@ -217,6 +217,7 @@ class EVENTVIEWS_EXPORT Prefs
KConfig *config() const;
void createNewColor(QColor &defColor, int seed);
private:
class Private;
Private *const d;
......
include_directories(${CMAKE_SOURCE_DIR}/calendarviews
)
set(createcolorgui_test createcolorgui_test.cpp)
kde4_add_executable(createcolorgui_test TEST ${createcolorgui_test})
target_link_libraries(createcolorgui_test
${QT_QTTEST_LIBRARY}
${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${KDE4_KDECORE_LIBS}
${KDE4_KDEUI_LIBS}
eventviews
)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "createcolorgui_test.h"
#include "prefs.h"
#include <kapplication.h>
#include <KCmdLineArgs>
#include <KLocalizedString>
#include <QVBoxLayout>
#include <QListWidget>
#include <QDebug>
CreateColorGui_test::CreateColorGui_test(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *vbox = new QVBoxLayout;
setLayout(vbox);
mListWidget = new QListWidget;
vbox->addWidget(mListWidget);
createListWidgetItem();
}
CreateColorGui_test::~CreateColorGui_test()
{
}
void CreateColorGui_test::createListWidgetItem()
{
EventViews::Prefs prefs;
mListWidget->clear();
for (int i = 0; i < 100; ++i) {
QListWidgetItem *item = new QListWidgetItem;
QColor defColor( 0x37, 0x7A, 0xBC );
prefs.createNewColor(defColor, i);
item->setBackgroundColor(defColor);
mListWidget->addItem(item);
}
}
int main (int argc, char **argv)
{
KCmdLineArgs::init(argc, argv, "CreateColorGui_test", 0, ki18n("CreateColorGui_test"),
"1.0", ki18n("Test creating color"));
KApplication app;
CreateColorGui_test *createColor = new CreateColorGui_test;
createColor->resize(800, 600);
createColor->show();
app.exec();
return 0;
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CREATECOLORGUI_TEST_H
#define CREATECOLORGUI_TEST_H
#include <QWidget>
class QListWidget;
class CreateColorGui_test : public QWidget
{
Q_OBJECT
public:
explicit CreateColorGui_test(QWidget *parent=0);
~CreateColorGui_test();
private:
void createListWidgetItem();
QListWidget *mListWidget;
};
#endif // CREATECOLORGUI_TEST_H
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