File: clicklabel.cpp

package info (click to toggle)
xca 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,328 kB
  • sloc: cpp: 30,584; sh: 341; xml: 74; makefile: 56; python: 34
file content (80 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (2)
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
/* vi: set sw=4 ts=4:
 *
 * Copyright (C) 2001 - 2007 Christian Hohnstaedt.
 *
 * All rights reserved.
 */

#include "clicklabel.h"

#include <QToolTip>
#include <QPalette>
#include <QColor>

void DoubleClickLabel::mouseDoubleClickEvent(QMouseEvent * e)
{
	QWidget::mouseDoubleClickEvent(e);
	if (clicktext.isEmpty())
		emit doubleClicked(text());
	else
		emit doubleClicked(clicktext);
}

void DoubleClickLabel::setClickText(QString s)
{
	clicktext = s;
}

ClickLabel::ClickLabel(QWidget *parent)
	:DoubleClickLabel(parent)
{
	QFont fnt( font() );
	fnt.setBold(true);
	setFont( fnt );
	setFrameShape( QLabel::Panel );
	setFrameShadow( QLabel::Sunken );
	setAlignment( Qt::AlignCenter );
	setToolTip( tr("Double click for details") );

	setAutoFillBackground(true);
	QPalette pal = palette();
	QColor col = QColor(0xff, 0xff, 0xff);
	pal.setColor(QPalette::Normal, QPalette::Window, col );
	pal.setColor(QPalette::Inactive, QPalette::Window, col );
	setPalette( pal );
	setTextFormat(Qt::PlainText);
}

void ClickLabel::setColor(const QColor &col)
{
	QPalette pal = palette();
	pal.setColor(QPalette::Normal, QPalette::WindowText, col );
	pal.setColor(QPalette::Inactive, QPalette::WindowText, col );
	setPalette( pal );
}

void ClickLabel::setRed()
{
	setColor( QColor( 192, 32, 32) );
}

void ClickLabel::setGreen()
{
	setColor( QColor( 32, 192, 32) );
}

void ClickLabel::disableToolTip()
{
	setToolTip(QString());
}

CopyLabel::CopyLabel(QWidget *parent)
	:DoubleClickLabel(parent)
{
	setFrameStyle(QFrame::StyledPanel);
	setTextFormat(Qt::PlainText);
	setTextInteractionFlags(
		Qt::TextSelectableByMouse |
		Qt::TextSelectableByKeyboard
	);
}