File: preferenceswidget.cpp

package info (click to toggle)
psi-plugins 1.5-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,368 kB
  • sloc: cpp: 42,063; xml: 714; ansic: 84; makefile: 61; sh: 12
file content (101 lines) | stat: -rw-r--r-- 4,018 bytes parent folder | download | duplicates (5)
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
#include "preferenceswidget.h"

PreferencesWidget::PreferencesWidget(const QColor &username_color,
                                     const QColor &post_id_color,
                                     const QColor &tag_color,
                                     const QColor &quote_color,
                                     const QColor &message_color,
                                     QWidget *parent)
    : QWidget(parent),
    now_changing_button(NULL),
    color_dialog(this),
    curr_username_color(username_color),
    curr_post_id_color(post_id_color),
    curr_tag_color(tag_color),
    curr_quote_color(quote_color),
    curr_message_color(message_color)
{
    connect(&color_dialog, SIGNAL(accepted()),
            this, SLOT(colorDialogOk()));
    connect(&color_dialog, SIGNAL(rejected()),
            this, SLOT(colorDialogCancel()));
    color_dialog.setModal(true);

    preferences_ui.setupUi(this);

    // @username
    preferences_ui.usernameColorButton->setStyleSheet(QString("background-color: %1;").arg(username_color.name()));
    connect(preferences_ui.usernameColorButton, SIGNAL(clicked()), this, SLOT(usernameColorClicked()));

    // #post/id
    preferences_ui.postColorButton->setStyleSheet(QString("background-color: %1;").arg(post_id_color.name()));
    connect(preferences_ui.postColorButton, SIGNAL(clicked()), this, SLOT(postColorClicked()));

    // *tag
    preferences_ui.tagColorButton->setStyleSheet(QString("background-color: %1;").arg(tag_color.name()));
    connect(preferences_ui.tagColorButton, SIGNAL(clicked()), this, SLOT(tagColorClicked()));

    // > quote
    preferences_ui.quoteColorButton->setStyleSheet(QString("background-color: %1;").arg(quote_color.name()));
    connect(preferences_ui.quoteColorButton, SIGNAL(clicked()), this, SLOT(quoteColorClicked()));

    // message
    preferences_ui.messageColorButton->setStyleSheet(QString("background-color: %1;").arg(message_color.name()));
    connect(preferences_ui.messageColorButton, SIGNAL(clicked()), this, SLOT(messageColorClicked()));
}

void PreferencesWidget::usernameColorClicked() {
    color_dialog.setCurrentColor(curr_username_color);
    showChangeButtonColorDialog(preferences_ui.usernameColorButton);
}

void PreferencesWidget::postColorClicked() {
    color_dialog.setCurrentColor(curr_post_id_color);
    showChangeButtonColorDialog(preferences_ui.postColorButton);
}

void PreferencesWidget::tagColorClicked() {
    color_dialog.setCurrentColor(curr_tag_color);
    showChangeButtonColorDialog(preferences_ui.tagColorButton);
}

void PreferencesWidget::quoteColorClicked() {
    color_dialog.setCurrentColor(curr_quote_color);
    showChangeButtonColorDialog(preferences_ui.quoteColorButton);
}

void PreferencesWidget::messageColorClicked() {
    color_dialog.setCurrentColor(curr_message_color);
    showChangeButtonColorDialog(preferences_ui.messageColorButton);
}


void PreferencesWidget::showChangeButtonColorDialog(QAbstractButton * button) {
    now_changing_button = button;
    color_dialog.show();
}

void PreferencesWidget::colorDialogOk() {
    if (now_changing_button) {
        QColor new_color = color_dialog.currentColor();
	now_changing_button->setStyleSheet(QString("background-color: %1;").arg(new_color.name()));

        if (now_changing_button == preferences_ui.usernameColorButton) {
            emit usernameColorChanged(new_color);
        } else if (now_changing_button == preferences_ui.postColorButton) {
            emit postColorChanged(new_color);
        } else if (now_changing_button == preferences_ui.tagColorButton) {
            emit tagColorChanged(new_color);
        } else if (now_changing_button == preferences_ui.quoteColorButton) {
            emit quoteColorChanged(new_color);
        } else if (now_changing_button == preferences_ui.messageColorButton) {
            emit messageColorChanged(new_color);
        }
    }

    now_changing_button = NULL;
}

void PreferencesWidget::colorDialogCancel() {
    now_changing_button = NULL;
}