bool TrayIcon::event(QEvent *event) { switch (event->type()) { case QEvent::Paint: draw(static_cast<QPaintEvent*>(event)); break; case QEvent::Resize: { QRect rect = iconGeometry(); xfitMan().moveWindow(mWindowId, rect.left(), rect.top()); } break; case QEvent::MouseButtonPress: event->accept(); break; default: break; } return QFrame::event(event); }
bool Manager::animateMinimize(bool iconify) { int style = Static::instance()->animationStyle(); switch (style) { case 1: { // Double twisting double back, with pike ;) if (!iconify) // No animation for restore. return true; // Go away quick. helperShowHide(false); tqApp->syncX(); TQRect r = iconGeometry(); if (!r.isValid()) return true; // Algorithm taken from Window Maker (http://www.windowmaker.org) int sx = geometry().x(); int sy = geometry().y(); int sw = width(); int sh = height(); int dx = r.x(); int dy = r.y(); int dw = r.width(); int dh = r.height(); double steps = 12; double xstep = double((dx-sx)/steps); double ystep = double((dy-sy)/steps); double wstep = double((dw-sw)/steps); double hstep = double((dh-sh)/steps); double cx = sx; double cy = sy; double cw = sw; double ch = sh; double finalAngle = 3.14159265358979323846; double delta = finalAngle / steps; TQPainter p(workspaceWidget()); p.setRasterOp(TQt::NotROP); for (double angle = 0; ; angle += delta) { if (angle > finalAngle) angle = finalAngle; double dx = (cw / 10) - ((cw / 5) * sin(angle)); double dch = (ch / 2) * cos(angle); double midy = cy + (ch / 2); TQPoint p1(int(cx + dx), int(midy - dch)); TQPoint p2(int(cx + cw - dx), p1.y()); TQPoint p3(int(cx + dw + dx), int(midy + dch)); TQPoint p4(int(cx - dx), p3.y()); grabXServer(); p.drawLine(p1, p2); p.drawLine(p2, p3); p.drawLine(p3, p4); p.drawLine(p4, p1); p.flush(); usleep(500); p.drawLine(p1, p2); p.drawLine(p2, p3); p.drawLine(p3, p4); p.drawLine(p4, p1); ungrabXServer(); cx += xstep; cy += ystep; cw += wstep; ch += hstep; if (angle >= finalAngle) break; } } break; case 2: { // KVirc style ? Maybe. For qwertz. if (!iconify) // No animation for restore. return true; // Go away quick. helperShowHide(false); tqApp->syncX(); int stepCount = 12; TQRect r(geometry()); int dx = r.width() / (stepCount * 2); int dy = r.height() / (stepCount * 2); TQPainter p(workspaceWidget()); p.setRasterOp(TQt::NotROP); for (int step = 0; step < stepCount; step++) { r.moveBy(dx, dy); r.setWidth(r.width() - 2 * dx); r.setHeight(r.height() - 2 * dy); grabXServer(); p.drawRect(r); p.flush(); usleep(200); p.drawRect(r); ungrabXServer(); } } break; default: { TQRect icongeom = iconGeometry(); if (!icongeom.isValid()) return true; TQRect wingeom = geometry(); TQPainter p(workspaceWidget()); p.setRasterOp(TQt::NotROP); #if 0 if (iconify) p.setClipRegion(TQRegion(workspaceWidget()->rect()) - wingeom); #endif grabXServer(); p.drawLine(wingeom.bottomRight(), icongeom.bottomRight()); p.drawLine(wingeom.bottomLeft(), icongeom.bottomLeft()); p.drawLine(wingeom.topLeft(), icongeom.topLeft()); p.drawLine(wingeom.topRight(), icongeom.topRight()); p.flush(); tqApp->syncX(); usleep(30000); p.drawLine(wingeom.bottomRight(), icongeom.bottomRight()); p.drawLine(wingeom.bottomLeft(), icongeom.bottomLeft()); p.drawLine(wingeom.topLeft(), icongeom.topLeft()); p.drawLine(wingeom.topRight(), icongeom.topRight()); ungrabXServer(); } break; } return true; }
void TrayIcon::draw(QPaintEvent* /*event*/) { Display* dsp = QX11Info::display(); XWindowAttributes attr; if (!XGetWindowAttributes(dsp, mIconId, &attr)) { qWarning() << "Paint error"; return; } XImage* ximage = XGetImage(dsp, mIconId, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap); if (!ximage) { qWarning() << " * Error image is NULL"; return; } // qDebug() << "Paint icon **************************************"; // qDebug() << " * XComposite: " << isXCompositeAvailable(); // qDebug() << " * Icon geometry:" << iconGeometry(); // qDebug() << " Icon"; // qDebug() << " * window id: " << hex << mIconId; // qDebug() << " * window name:" << xfitMan().getName(mIconId); // qDebug() << " * size (WxH): " << attr.width << "x" << attr.height; // qDebug() << " * pos (XxY): " << attr.x << attr.y; // qDebug() << " * color depth:" << attr.depth; // qDebug() << " XImage"; // qDebug() << " * size (WxH): " << ximage->width << "x" << ximage->height; // switch (ximage->format) // { // case XYBitmap: qDebug() << " * format: XYBitmap"; break; // case XYPixmap: qDebug() << " * format: XYPixmap"; break; // case ZPixmap: qDebug() << " * format: ZPixmap"; break; // } // qDebug() << " * color depth: " << ximage->depth; // qDebug() << " * bits per pixel:" << ximage->bits_per_pixel; //const uchar* d =(uchar*) ximage->data; QImage image = QImage((const uchar*) ximage->data, ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_ARGB32_Premultiplied); // Draw QImage ........................... QPainter painter(this); QRect iconRect = iconGeometry(); if (image.size() != iconRect.size()) { image = image.scaled(iconRect.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); QRect r = image.rect(); r.moveCenter(iconRect.center()); iconRect = r; } // qDebug() << " Draw rect:" << iconRect; painter.drawImage(iconRect, image); XDestroyImage(ximage); // debug << "End paint icon **********************************"; }