summaryrefslogtreecommitdiff
path: root/noncore/settings/appearance2/editScheme.cpp
blob: 2453c7ba05fe026ea7ab76f03c68e0d332acc849 (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
/**********************************************************************
** EditScheme
**
** Dialog for editing color scheme
**
** Copyright (C) 2002, Dan Williams
**                    williamsdr@acm.org
**                    http://draknor.net
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/

#include "editScheme.h"

#include "opie/colorpopupmenu.h"

#include <qaction.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qpopupmenu.h>
#include <qscrollview.h>
#include <qtoolbutton.h>

EditScheme::EditScheme( QWidget* parent,  const char* name, bool modal, WFlags fl,
                        int max, QString list[], QString colors[] )
    : QDialog( parent, name, modal, fl )
{
    setCaption( tr( "Edit scheme" ) );
    QGridLayout* layout = new QGridLayout( this );
    layout->setSpacing( 4 );
    layout->setMargin( 4 );


    maxCount = max;
    int i;
    QLabel* label;
    ColorPopupMenu* colorPopupMenu;
    for ( i = 0; i < max; i++ )
    {
        colorList[i] = colors[i];
        surfaceList[i] = list[i];
        label = new QLabel( tr( surfaceList[i] ), this );
        layout->addWidget( label, i, 0 );
        colorButtons[i] = new QToolButton( this, list[i] );
        colorButtons[i]->setPalette( QPalette( QColor( colors[i] ) ) );
        layout->addWidget( colorButtons[i], i, 1 );

        colorPopupMenu = new ColorPopupMenu( colors[i], 0, list[i] );
        colorButtons[i]->setPopup( colorPopupMenu );
        colorButtons[i]->setPopupDelay( 0 );
        connect( colorPopupMenu, SIGNAL( colorSelected( const QColor& ) ), this, SLOT( changeColor( const QColor& ) ) );
    }
}

EditScheme::~EditScheme()
{
}

void EditScheme::changeColor( const QColor& color )
{
    QString name( sender()->name() );
    int i;

    for ( i = 0; i < maxCount; i++ )
    {
        if ( name == colorButtons[i]->name() )
        {
            break;
        }
    }
    if ( i < maxCount && name == colorButtons[i]->name() )
    {
        colorList[i] = color.name();
        colorButtons[i]->setPalette( QPalette( QColor( colorList[i] ) ) );
    }
}