#include "VButton.h" #include #include #include #include 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) { // Need to set the pushbutton text to correctly handle those buttons which usually // don't change (tab, shift, caps, Fn, ...) 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"