You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
3.1 KiB
165 lines
3.1 KiB
#include "VButton.h"
|
|
#include <tqvbox.h>
|
|
#include <tqfont.h>
|
|
#include <tdeconfig.h>
|
|
#include <tdeapplication.h>
|
|
|
|
double VButton::pw=552.0;
|
|
double VButton::ph=235.0;
|
|
|
|
VButton::VButton(TQWidget *parent, const char *name): TQPushButton (parent,name)
|
|
{
|
|
TDEConfig *cfg = TDEApplication::kApplication()->config();
|
|
TQString keysC = cfg->readEntry("keysColor", "#f0f0f0");
|
|
setColor(TQColor(keysC));
|
|
setFocusPolicy(TQ_NoFocus);
|
|
resize(30,30);
|
|
press=false;
|
|
}
|
|
|
|
VButton::~VButton()
|
|
{
|
|
}
|
|
|
|
void VButton::shiftCapsPressed(bool shift, bool caps)
|
|
{
|
|
if (isAlpha)
|
|
{
|
|
// Alpha button, both shift and caps affect its state
|
|
if (shift ^ caps)
|
|
{
|
|
TQPushButton::setText(shiftText);
|
|
}
|
|
else
|
|
{
|
|
TQPushButton::setText(lowerText);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Non alpha button, only shift affects its state
|
|
if (shift)
|
|
{
|
|
TQPushButton::setText(shiftText);
|
|
}
|
|
else
|
|
{
|
|
TQPushButton::setText(lowerText);
|
|
}
|
|
}
|
|
}
|
|
|
|
void VButton::setText(const TQString& text)
|
|
{
|
|
TQPushButton::setText(text);
|
|
lowerText = text;
|
|
isAlpha = text.length() == 1 && (text.upper() != text);
|
|
}
|
|
|
|
void VButton::setShiftText(const TQString& text)
|
|
{
|
|
shiftText=text;
|
|
}
|
|
|
|
void VButton::setColor(const TQColor &color)
|
|
{
|
|
setPaletteBackgroundColor(color);
|
|
// Need to set TQColorGroup::Button color as well, otherwise the actual
|
|
// color of the key does not change until the next restart of the application.
|
|
TQPalette plt = palette();
|
|
plt.setColor(TQPalette::Active, TQColorGroup::Button, color);
|
|
plt.setColor(TQPalette::Inactive, TQColorGroup::Button, color);
|
|
plt.setColor(TQPalette::Disabled, TQColorGroup::Button, color);
|
|
setPalette(plt);
|
|
}
|
|
|
|
void VButton::setKeyCode(unsigned int keycode)
|
|
{
|
|
this->keycode=keycode;
|
|
}
|
|
|
|
unsigned int VButton::getKeyCode()
|
|
{
|
|
return this->keycode;
|
|
}
|
|
|
|
void VButton::sendKey()
|
|
{
|
|
emit keyClick(keycode);
|
|
}
|
|
|
|
void VButton::reposition(int width, int height)
|
|
{
|
|
double dx=pw/orig_size.x();
|
|
double dy=ph/orig_size.y();
|
|
double sdx=pw/orig_size.width();
|
|
double sdy=ph/orig_size.height();
|
|
move((int)(width/dx),(int)(height/dy));
|
|
resize((int)(width/sdx), (int)(height/sdy));
|
|
}
|
|
|
|
void VButton::res()
|
|
{
|
|
orig_size=geometry();
|
|
}
|
|
|
|
void VButton::enterEvent(TQEvent *e)
|
|
{
|
|
TQPushButton::enterEvent(e);
|
|
inside = true;
|
|
}
|
|
|
|
void VButton::leaveEvent(TQEvent *e)
|
|
{
|
|
TQPushButton::leaveEvent(e);
|
|
inside = false;
|
|
}
|
|
|
|
void VButton::mousePressEvent(TQMouseEvent *e)
|
|
{
|
|
press=true;
|
|
TQPushButton::mousePressEvent(e);
|
|
if (!isToggleButton())
|
|
{
|
|
// non toggle buttons need to send the key here
|
|
sendKey();
|
|
startTimer(500);
|
|
}
|
|
}
|
|
|
|
void VButton::mouseReleaseEvent(TQMouseEvent *e)
|
|
{
|
|
press=false;
|
|
TQPushButton::mouseReleaseEvent(e);
|
|
if (hitButton(e->pos()) && isToggleButton())
|
|
{
|
|
// toggle buttons need to send the key here because the underlying pushbutton state
|
|
// is only updated on mouse release
|
|
sendKey();
|
|
}
|
|
killTimers();
|
|
inrpt=false;
|
|
}
|
|
|
|
void VButton::timerEvent(TQTimerEvent *)
|
|
{
|
|
if (!press)
|
|
{
|
|
inrpt=false;
|
|
return;
|
|
}
|
|
if (press && !inrpt)
|
|
{
|
|
inrpt=true;
|
|
startTimer(120);
|
|
return;
|
|
}
|
|
if (inside)
|
|
{
|
|
// Send key only if the mouse is still inside the button rectangle
|
|
sendKey();
|
|
}
|
|
}
|
|
|
|
#include "VButton.moc"
|