File: checkmenu.C

package info (click to toggle)
qps 1.9.3-3.1
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 456 kB
  • ctags: 1,282
  • sloc: cpp: 8,565; makefile: 98; sh: 1
file content (53 lines) | stat: -rw-r--r-- 1,531 bytes parent folder | download | duplicates (3)
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
// checkmenu.C
//
// This program is free software. See the file COPYING for details.
// Author: Mattias Engdegrd, 1997-1999

// a version of QPopupMenu where checked items look better in Motif
// This doesn't look well with all fonts (designed for Helvetica Bold 12 at
// 75dpi).

// In WindowsStyle the behaviour is identical to that of QPopupMenu.

#include "checkmenu.h"
#include <qfontmetrics.h>

// Motif style parameters (snarfed from Qt sources)

static const int motifItemFrame		= 2;	// menu item frame width
static const int motifItemHMargin	= 3;	// menu item hor text margin
static const int motifItemVMargin	= 2;	// menu item ver text margin

CheckMenu::CheckMenu(QWidget *parent)
          : QPopupMenu(parent)
{}

#if QT_VERSION < 200

void CheckMenu::paintCell(QPainter *p, int row, int col)
{
    int id = idAt(row);
    // only do this if we're in Motif mode
    if(col == 0 && isItemChecked(id) && style() == MotifStyle) {
	int ch = cellHeight(row);

	int x0 = motifItemFrame + motifItemHMargin;
	int y0 = motifItemVMargin;

	QFontMetrics fm = fontMetrics();
	// let the tick be an M wide and go from baseline to ascent
	int w = fm.width('M');
	int h = fm.height();
	int a = fm.ascent() - 4;
	y0 += (ch - h) / 2 + 1;

	// this is tuned for Helvetica Bold 12, but should work otherwise too
	if(font().bold())
	    p->setPen(QPen(colorGroup().text(), 2));
	p->drawLine(x0, y0 + a * 2 / 3, x0 + w / 3, y0 + a);
	p->drawLine(x0 + w / 3, y0 + a, x0 + w, y0);
    } else
	QPopupMenu::paintCell(p, row, col);
}

#endif