Beispiel #1
0
ClientFrame::ClientFrame(bool showIcon, bool showMaxButton, QWidget* parent)
        : QWidget(parent) {
    Config* cfg = Config::getInstance();

    // Inicializamos los atributos
    this->mouseMask = 0;

    this->titlebar          = new QLabel(this);
    this->title             = new QLabel(this);
    this->topBorder         = new QLabel(this);
    this->topLeftBorder     = new QLabel(this);
    this->topRightBorder    = new QLabel(this);
    this->bottomBorder      = new QLabel(this);
    this->bottomLeftBorder  = new QLabel(this);
    this->bottomRightBorder = new QLabel(this);
    this->leftBorder        = new QLabel(this);
    this->leftTopBorder     = new QLabel(this);
    this->leftBottomBorder  = new QLabel(this);
    this->rightBorder       = new QLabel(this);
    this->rightTopBorder    = new QLabel(this);
    this->rightBottomBorder = new QLabel(this);

    this->minimizeButton    = new QPushButton(this);
    this->maximizeButton    = new QPushButton(this);
    this->exitButton        = new QPushButton(this);
    this->icon              = new QLabel(this);

    // Hacemos que las imágenes se ajusten a sus contenedores
    this->titlebar->setScaledContents(true);
    this->topBorder->setScaledContents(true);
    this->topLeftBorder->setScaledContents(true);
    this->topRightBorder->setScaledContents(true);
    this->bottomBorder->setScaledContents(true);
    this->bottomLeftBorder->setScaledContents(true);
    this->bottomRightBorder->setScaledContents(true);
    this->leftBorder->setScaledContents(true);
    this->leftTopBorder->setScaledContents(true);
    this->leftBottomBorder->setScaledContents(true);
    this->rightBorder->setScaledContents(true);
    this->rightTopBorder->setScaledContents(true);
    this->rightBottomBorder->setScaledContents(true);
    this->icon->setScaledContents(true);

    // Ponemos los cursores para los bordes
    this->topBorder->setCursor(Qt::SizeVerCursor);
    this->bottomBorder->setCursor(Qt::SizeVerCursor);
    this->leftBorder->setCursor(Qt::SizeHorCursor);
    this->rightBorder->setCursor(Qt::SizeHorCursor);

    this->topLeftBorder->setCursor(Qt::SizeFDiagCursor);
    this->leftTopBorder->setCursor(Qt::SizeFDiagCursor);
    this->bottomRightBorder->setCursor(Qt::SizeFDiagCursor);
    this->rightBottomBorder->setCursor(Qt::SizeFDiagCursor);

    this->topRightBorder->setCursor(Qt::SizeBDiagCursor);
    this->rightTopBorder->setCursor(Qt::SizeBDiagCursor);
    this->leftBottomBorder->setCursor(Qt::SizeBDiagCursor);
    this->bottomLeftBorder->setCursor(Qt::SizeBDiagCursor);

    // Establecemos el nombre de los distintos elementos configurables desde el
    // archivo de configuración "style.qss"
    this->setObjectName("ClientFrame");
    this->titlebar->setObjectName("titlebar");
    this->title->setObjectName("title");
    this->topBorder->setObjectName("topBorder");
    this->topLeftBorder->setObjectName("topLeftBorder");
    this->topRightBorder->setObjectName("topRightBorder");
    this->bottomBorder->setObjectName("bottomBorder");
    this->bottomLeftBorder->setObjectName("bottomLeftBorder");
    this->bottomRightBorder->setObjectName("bottomRightBorder");
    this->rightBorder->setObjectName("rightBorder");
    this->rightTopBorder->setObjectName("rightTopBorder");
    this->rightBottomBorder->setObjectName("rightBottomBorder");
    this->leftBorder->setObjectName("leftBorder");
    this->leftTopBorder->setObjectName("leftTopBorder");
    this->leftBottomBorder->setObjectName("leftBottomBorder");
    this->minimizeButton->setObjectName("minimizeButton");
    this->maximizeButton->setObjectName("maximizeButton");
    this->exitButton->setObjectName("exitButton");
    this->icon->setObjectName("icon");

    // Mostramos o no los distintos elementos según corresponda
    this->icon->setVisible(showIcon);
    this->maximizeButton->setVisible(showMaxButton);

    // Lanzamos señales cuando se pulsa un botón
    connect(this->minimizeButton, SIGNAL(clicked()), this,
            SIGNAL(minimizedFrame()));
    connect(this->maximizeButton, SIGNAL(clicked()), this,
            SIGNAL(maximizedFrame()));
    connect(this->exitButton, SIGNAL(clicked()),this, SIGNAL(closedFrame()));

    // Aplicamos el estilo a la ventana
    this->setStyleSheet(cfg->getStyle());

    // Ajustamos el tamaño de los distintos elementos
    this->title->resize(this->title->width(), cfg->getTitlebarWidth()
            + cfg->getTopBorderWidth());
    this->minimizeButton->resize(this->minimizeButton->iconSize());
    this->maximizeButton->resize(this->maximizeButton->iconSize());
    this->exitButton->resize(this->exitButton->iconSize());
    this->icon->resize(cfg->getIconSize(), cfg->getIconSize());

    // Establecemos la alineación de los elementos de la barra de título
    this->setVerticalAling(this->minimizeButton, cfg->getMinimizeButtonAling());
    this->setVerticalAling(this->maximizeButton, cfg->getMaximizeButtonAling());
    this->setVerticalAling(this->exitButton, cfg->getExitButtonAling());
    this->setVerticalAling(this->title, Config::TOP);
    this->setVerticalAling(this->icon, Config::CENTER);
}
Beispiel #2
0
void XWindow::addFrame()
{
    if(!this->haveFrame() && this->needFrame())
    {
        Config* cfg = Config::getInstance();

        //revisamos si ponemos boton de maximizar
        bool maximize = true;
        //si el min width es igual al max width entonces no le podemos cambiar el tamaño y tampoco maximizarlo
        if (client->getMaxWidth() == client->getMinWidth() && client->getMaxHeight() == client->getMinHeight())
        {
            maximize = false;
        }

        // Creamos el marco con la posición y tamaño necesarios
        setTaskBar();
        this->frame = new ClientFrame(cfg->isIconVisible(), maximize, in_taskbar_);


        this->setX(this->client->getX());
        this->setY(this->client->getY());
        this->setWidth(this->client->getWidth() + cfg->getLeftBorderWidth()
                + cfg->getRightBorderWidth());
        this->setHeight(this->client->getHeight() + cfg->getTitlebarWidth()
                + cfg->getTopBorderWidth() + cfg->getBottomBorderWidth());

        // Guardamos el ID del frame
        this->frameID = this->frame->winId();

        // Hacemos al marco padre de la ventana a decorar
        XReparentWindow(QX11Info::display(), this->clientID,
                this->frameID,
                cfg->getLeftBorderWidth(),
                cfg->getTitlebarWidth() + cfg->getTopBorderWidth());

        // Como ahora la ventana no es hija de la root window ya no recibimos
        // sus eventos. Hacemos que se sigan recibiendo.

        XSelectInput(QX11Info::display(), this->frameID,
                  ButtonPressMask | ButtonReleaseMask | ButtonMotionMask
                | PointerMotionMask
                | KeyPressMask | KeyReleaseMask | KeymapStateMask
                | EnterWindowMask | LeaveWindowMask | FocusChangeMask
                | ExposureMask | SubstructureRedirectMask
                | StructureNotifyMask | SubstructureNotifyMask
                | PropertyChangeMask);


        //XGrabButton(QX11Info::display(), AnyButton, AnyModifier,  this->clientID, False, ButtonPressMask|ButtonReleaseMask, GrabModeAsync, GrabModeSync, None, None);
        XSelectInput(QX11Info::display(), this->clientID, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask|ButtonMotionMask|ButtonReleaseMask);


        // Conectamos signals y slots
        connect(this->frame, SIGNAL(resizedFrame(int, int)), this, SLOT(resizedFrame(int, int)));
        connect(this->frame, SIGNAL(minimizedFrame()), this, SLOT(minimizedFrame()));
        connect(this->frame, SIGNAL(minimizedVisibleFrame()), this, SLOT(minimizedVisibleFrame()));
        connect(this->frame, SIGNAL(maximizedFrame()), this, SLOT(maximizedFrame()));
        connect(this->frame, SIGNAL(closedFrame()), this, SLOT(closedFrame()));
        connect(this->frame, SIGNAL(isMaximized()), this, SLOT(isMaximized()));

        // Añadimos el cliente al save-set para que si el WM se cierra
        // inesperadamente no desaparezcan los clientes
        XAddToSaveSet(QX11Info::display(), this->clientID);
    }