summaryrefslogtreecommitdiffstats
path: root/lib/kofficeui/tests/coloraction_test.cpp
blob: 5e38c950c9e236eaa372e9a13bbad78485c46475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* This file is part of the KDE project
   Copyright (C) 1999 by Dirk A. Mueller <dmuell@gmx.net>
   Copyright (C) 2002 Werner Trobin <trobin@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include <tqlayout.h>
#include <tqvgroupbox.h>
#include <tqpopupmenu.h>
#include <tqmenubar.h>

#include <kdebug.h>
#include <tdetoolbar.h>
#include <kiconloader.h>
#include <tdeapplication.h>
#include <KoTooluButton.h>
#include <coloraction_test.h>

#include <stdlib.h>
#include <time.h>


TopLevel::TopLevel( TQWidget* parent, const char* name) : TQMainWindow( parent, name )
{
    setCaption( TQString::fromLatin1( "KColorAction test application" ) );

    TQWidget *w = new TQWidget( this );
    setCentralWidget( w );

    TQBoxLayout* l = new TQHBoxLayout( w, KDialog::marginHint(), KDialog::spacingHint() );
    TQGroupBox* b1 = new TQVGroupBox( TQString::fromLatin1( "KoColorPanel 1" ), w );
    panel = new KoColorPanel( b1, "panel1" );
    connect( panel, TQ_SIGNAL( colorSelected( const TQColor& ) ), TQ_SLOT( slotColorSelected( const TQColor& ) ) );
    //panel->insertDefaultColors();
    l->addWidget( b1 );

    b1 = new TQVGroupBox( TQString::fromLatin1( "KoColorPanel 2" ), w );

    ( void ) new KoColorPanel( b1, "panel2" );
    l->addWidget( b1 );

    TQPopupMenu* file = new TQPopupMenu( this );
    menuBar()->insertItem( "&File", file );

    file->insertItem( "Custom + Default", KoColorPanel::createColorPopup( KoColorPanel::CustomColors, TQt::red, this,
                                                                          TQ_SLOT( slotColorSelected( const TQColor& ) ), file, "blah" ) );
    file->insertItem( "Custom", KoColorPanel::createColorPopup( KoColorPanel::CustomColors, TQColor(), this,
                                                                TQ_SLOT( slotColorSelected( const TQColor& ) ), file, "blah" ) );
    file->insertItem( "Plain + Default", KoColorPanel::createColorPopup( KoColorPanel::Plain, TQt::green, this,
                                                                         TQ_SLOT( slotColorSelected( const TQColor& ) ), file, "blah" ) );
    file->insertItem( "Plain", KoColorPanel::createColorPopup( KoColorPanel::Plain, TQColor(), this,
                                                               TQ_SLOT( slotColorSelected( const TQColor& ) ), file, "blah" ) );
    file->insertSeparator();
    file->insertItem( "Default Colors", this, TQ_SLOT( defaultColors() ), CTRL+Key_D );
    file->insertItem( "Insert Random Color", this, TQ_SLOT( insertRandomColor() ), CTRL+Key_R );
    file->insertSeparator();
    file->insertItem( "Clear", this, TQ_SLOT( clearColors() ), CTRL+Key_C );
    file->insertSeparator();
    file->insertItem( "&Quit", tqApp, TQ_SLOT( closeAllWindows() ), CTRL+Key_Q );

    TDEToolBar* toolBar = new TDEToolBar( this );
    addDockWindow( toolBar );
    ( void ) new KoToolButton( "color_fill", 1, toolBar, "funky button", "Fill Color" );
}

void TopLevel::insertRandomColor()
{
    panel->insertColor( tqRgb( rand() % 256, rand() % 256, rand() % 256 ) );
}

void TopLevel::defaultColors()
{
    panel->insertDefaultColors();
}

void TopLevel::clearColors()
{
    panel->clear();
}

void TopLevel::slotColorSelected( const TQColor& color )
{
    kdDebug() << "#### selected: " << color.name() << endl;
}


int main( int argc, char ** argv )
{
    srand( time( 0 ) );

    TDEApplication a( argc, argv, "KColorAction Test" );
    TopLevel *toplevel = new TopLevel( 0, "coloractiontest" );
    a.setMainWidget( toplevel );
    toplevel->show();
    return a.exec();
}

#include <coloraction_test.moc>