summaryrefslogtreecommitdiffstats
path: root/kopete/kopete/kopeteballoon.cpp
blob: c961a91a5dab30c001eeb6d06f1cb21b91f2c6b9 (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
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
    kopeteballoon.cpp  -  Nice Balloon

    Copyright (c) 2002      by Duncan Mac-Vicar Prett <duncan@kde.org>

    Kopete    (c) 2002-2005      by the Kopete developers  <kopete-devel@kde.org>

    Portions of this code based on Kim Applet code
    Copyright (c) 2000-2002 by Malte Starostik        <malte@kde.org>

    *************************************************************************
    *                                                                       *
    * This program is free software; you can redistribute it and/or modify  *
    * it under the terms of the GNU General Public License as published by  *
    * the Free Software Foundation; either version 2 of the License, or     *
    * (at your option) any later version.                                   *
    *                                                                       *
    *************************************************************************
*/

#include <tqpointarray.h>
#include <tqpushbutton.h>
#include <tqtooltip.h>
#include <tqlayout.h>
#include <tqtimer.h>

#include <tdeversion.h>
#include <kglobalsettings.h>

#include <kapplication.h>
#include <kdialog.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include <kprotocolinfo.h>
#include <kurl.h>
#include <krun.h>

#include "kopeteballoon.h"
#include "systemtray.h"
#include "kopeteprefs.h"

KopeteActiveLabel::KopeteActiveLabel( TQWidget *parent, const char *name )
	: KActiveLabel( parent, name ) 
{
}

KopeteActiveLabel::KopeteActiveLabel( const TQString& text, TQWidget *parent,
	const char *name ) : KActiveLabel( text, parent, name )
{
}

void KopeteActiveLabel::openLink( const TQString& link )
{
	KURL url( link );
	TQString protocol = url.protocol();
	
	if ( protocol == "mailto" )
		kapp->invokeMailer(url);
	else 
	{
		if ( KProtocolInfo::protocolClass( protocol ) == ":internet" ) // http, ftp, etc.
			new KRun( url, this );
	}
}

KopeteBalloon::KopeteBalloon(const TQString &text, const TQString &pix)
: TQWidget(0L, "KopeteBalloon", WStyle_StaysOnTop | WStyle_Customize |
	WStyle_NoBorder | WStyle_Tool | WX11BypassWM)
{
	setCaption("");

	TQVBoxLayout *BalloonLayout = new TQVBoxLayout(this, 22,
		KDialog::spacingHint(), "BalloonLayout");

	// BEGIN Layout1
	TQHBoxLayout *Layout1 = new TQHBoxLayout(BalloonLayout,
		KDialog::spacingHint(), "Layout1");
	//TQLabel *mCaption = new TQLabel(text, this, "mCaption");
	KopeteActiveLabel *mCaption = new KopeteActiveLabel(text, this, "mCaption");
	mCaption->setPalette(TQToolTip::palette());
	mCaption->setSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum );

	if (!pix.isEmpty())
	{
		TQLabel *mImage = new TQLabel(this, "mImage");
		mImage->setScaledContents(FALSE);
		mImage->setPixmap(locate("data", pix));

		Layout1->addWidget(mImage);
	}
	Layout1->addWidget(mCaption);
	// END Layout1


	// BEGIN Layout2
	TQHBoxLayout *Layout2 = new TQHBoxLayout(BalloonLayout,
		KDialog::spacingHint(), "Layout2");
	TQPushButton *mViewButton = new TQPushButton(i18n("to view", "View"), this,
		"mViewButton");
	TQPushButton *mIgnoreButton = new TQPushButton(i18n("Ignore"), this,
		"mIgnoreButton");

	Layout2->addStretch();
	Layout2->addWidget(mViewButton);
	Layout2->addWidget(mIgnoreButton);
	Layout2->addStretch();
	// END Layout2

	setPalette(TQToolTip::palette());
	setAutoMask(TRUE);

	connect(mViewButton, TQT_SIGNAL(clicked()),
		this, TQT_SIGNAL(signalButtonClicked()));
	connect(mViewButton, TQT_SIGNAL(clicked()),
		this, TQT_SLOT(deleteLater()));
	connect(mIgnoreButton, TQT_SIGNAL(clicked()),
		this, TQT_SIGNAL(signalIgnoreButtonClicked()));
	connect(mIgnoreButton, TQT_SIGNAL(clicked()),
		this, TQT_SLOT(deleteLater()));
	connect(mCaption, TQT_SIGNAL(linkClicked(const TQString &)),
		this, TQT_SIGNAL(signalIgnoreButtonClicked()));
	connect(mCaption, TQT_SIGNAL(linkClicked(const TQString &)),
		this, TQT_SLOT(deleteLater()));
	
	KopetePrefs *p = KopetePrefs::prefs();
	// Autoclose balloon 
	if (p->balloonClose())
		TQTimer::singleShot( p->balloonCloseDelay() * 1000, this, TQT_SIGNAL( signalTimeout( ) ) );
}

void KopeteBalloon::setAnchor(const TQPoint &anchor)
{
	mAnchor = anchor;
	updateMask();
}

void KopeteBalloon::updateMask()
{
	TQRegion mask(10, 10, width() - 20, height() - 20);

	TQPoint corners[8] = {
		TQPoint(width() - 50, 10),
		TQPoint(10, 10),
		TQPoint(10, height() - 50),
		TQPoint(width() - 50, height() - 50),
		TQPoint(width() - 10, 10),
		TQPoint(10, 10),
		TQPoint(10, height() - 10),
		TQPoint(width() - 10, height() - 10)
	};

	for (int i = 0; i < 4; ++i)
	{
		TQPointArray corner;
		corner.makeArc(corners[i].x(), corners[i].y(), 40, 40,
			i * 16 * 90, 16 * 90);
		corner.resize(corner.size() + 1);
		corner.setPoint(corner.size() - 1, corners[i + 4]);
		mask -= corner;
	}

	// get screen-geometry for screen our anchor is on
	// (geometry can differ from screen to screen!
		TQRect deskRect = TDEGlobalSettings::desktopGeometry(mAnchor);

	bool bottom = (mAnchor.y() + height()) > ((deskRect.y() + deskRect.height()-48));
	bool right = (mAnchor.x() + width()) > ((deskRect.x() + deskRect.width()-48));

	TQPointArray arrow(4);
	arrow.setPoint(0, TQPoint(right ? width() : 0, bottom ? height() : 0));
	arrow.setPoint(1, TQPoint(right ? width() - 10 : 10,
		bottom ? height() - 30 : 30));
	arrow.setPoint(2, TQPoint(right ? width() - 30 : 30,
		bottom ? height() - 10 : 10));
	arrow.setPoint(3, arrow[0]);
	mask += arrow;
	setMask(mask);

	move( right ? mAnchor.x() - width() : ( mAnchor.x() < 0 ? 0 : mAnchor.x() ),
	      bottom ? mAnchor.y() - height() : ( mAnchor.y() < 0 ? 0 : mAnchor.y() )  );

	//kdDebug(14000) << k_funcinfo << "finalpos: x=" << x() << ", y=" << y() << endl;
}

#include "kopeteballoon.moc"
// vim: set noet ts=4 sts=4 sw=4: