File: selind-kde.cpp

package info (click to toggle)
xkbsel 0.12-8
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,568 kB
  • ctags: 844
  • sloc: sh: 6,829; ansic: 5,760; cpp: 432; makefile: 332; lex: 284; sed: 93
file content (150 lines) | stat: -rw-r--r-- 3,115 bytes parent folder | download
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* $Id: selind-kde.cpp,v 1.3 1999/08/05 17:16:40 stano Exp $ 

   xkbsel main widget

   (C) 1999 Stanislav Meduna <stano@eunet.sk>
*/

#include <selind-kde.h>
#include <kbdselmenu-kde.h>

#include <qfont.h>
#include <kapp.h>
#include <qpushbutton.h>
#include <qtooltip.h>

#include <xkbselx.h>

#include <stdio.h>
#include <libintl.h>

#define _(s) gettext(s)

void MainToolTip::maybeTip(const QPoint &pos)
{
	tip(QRect(pos.x(), pos.y(), 1, 1), _("XKB keyboard selector"));
}


void SelBtn::mousePressEvent( QMouseEvent *ev )
{
	if (ev->button() & 2)
	{
		if (ev->type() == Event_MouseButtonPress)
			optionsRequested();
	}
	else
		QPushButton::mousePressEvent(ev);
}


OptionsPopMenu::OptionsPopMenu(QWidget *parent, const char *name)
 : QPopupMenu(parent, name) 
{
	setFont(QFont("Courier", 10, QFont::Normal));
	insertItem(_("Quit xkbsel"));
        connect(this, SIGNAL(activated(int)), SLOT(selected(int)));

}

void OptionsPopMenu::selected(int idx)
{
	KApplication::getKApplication()->quit();
}


SelInd::SelInd(QWidget *parent, const char *name)
  : QWidget(parent, name),
    menu(0), opt_menu(0), selBtn(0), commBtn(0), toolTip(0)
{
	setMinimumSize(32, 16);
	setMaximumSize(128, 32);

	menu = new KbdSelPopMenu(0, "menu");
	opt_menu = new OptionsPopMenu(0, "opt_menu");
	selBtn = new SelBtn(this, "selector");
	commBtn = new QPushButton(this, "communicator");

	selBtn->setGeometry(0, 0, width()-1, height()-1);
	selBtn->setFont(QFont("Courier", 10, QFont::Normal));
	selBtn->setText("Text");
	commBtn->move(0, selBtn->y()+selBtn->height());
	commBtn->resize(width(), height()-selBtn->height());
	toolTip = new MainToolTip(selBtn);
}

SelInd::~SelInd()
{
	// Announce we are no more here
	notify_me(KApplication::getKApplication()->getDisplay(),
		commBtn->winId(),
		0);

	delete commBtn;
	delete selBtn;
	delete menu;
}

void SelInd::resizeEvent(QResizeEvent *)
{
	selBtn->setGeometry(0, 0, width()-1, height()-1);
	commBtn->move(0, selBtn->y()+selBtn->height());
	commBtn->resize(width(), height()-selBtn->height());
}


int SelInd::constructAll()
{
	int r;

	// construct our menu
	r = menu->constructMenu();
	if (r < 0)
		return r;

	// The indicator button pops the menu on left button press
	connect(selBtn, SIGNAL(pressed()), this, SLOT(popupKbdSel()));

	// ... and options menu on the right one
	connect(selBtn, SIGNAL(optionsRequested()), this, SLOT(popupOptions()));

	// And the communicator redisplays the current selection
	connect(commBtn, SIGNAL(pressed()), this, SLOT(displayCurSel()));

	// Announce we are here
	notify_me(KApplication::getKApplication()->getDisplay(),
		commBtn->winId(),
		1);

	// Current selection
	displayCurSel();
}

void SelInd::popupKbdSel()
{
	menu->popup(QPoint(x(), y()));
	selBtn->setDown(false);
}

void SelInd::popupOptions()
{
	opt_menu->popup(QPoint(x(), y()));
}


void SelInd::displayCurSel()
{
	int r;
	int found;

	sel_info_t sel;

	r = get_current_sel(KApplication::getKApplication()->getDisplay(), &sel, &found);

	selBtn->setText((!r && found) ? sel.shortcut : _("none"));
}

void SelInd::quitNow()
{
	KApplication::getKApplication()->quit();
}