📄 normalzoomstate.cpp~
字号:
/*************************************************************************** * Copyright (C) 2006 by the KSmoothDock team * * dangvd@yahoo.com * * * * 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. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/#include "normalzoomstate.h"#include <iostream>#include <unistd.h>#include <qapplication.h>#include <qbitmap.h>#include <qpainter.h>#include <kpixmapeffect.h>#include <kwin.h>#include "ksmoothdock.h"#include "launcher.h"#include "showdesktop.h"/// PUBLIC ////** * Constructors */NormalZoomState::NormalZoomState(KSmoothDock* dock) : DockState(dock) { m_w = 0; m_h = 0; m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(updateZoom())); m_animationNumSteps = 10; if (m_dock->m_isAutohide) { m_isHidden = true; } else { m_isHidden = false; }}/** * Dock created event */void NormalZoomState::dockCreatedEvent() { if (m_dock->m_isAutohide && m_isHidden) m_dock->setDockBelow();}/** * Update the layout */void NormalZoomState::updateLayout(bool reset) { m_lastFocusedItemIndex = -1; m_clickedLauncherIndex = -1; m_itemsSize.clear(); m_itemsSizeIncrement.clear(); for (unsigned int i = 0; i < m_dock->m_items.size(); i++) { m_itemsSize.push_back(m_dock->m_smallIconSize); m_itemsSizeIncrement.push_back(0); } m_firstIndexToUpdate = 0; m_lastIndexToUpdate = m_dock->m_items.size() - 1; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); int old_w = m_w; int old_h = m_h; m_w = m_h = 0; if (m_dock->m_orientation == Qt::Horizontal) { // calculate w and h for (unsigned int i = 0; i < m_dock->m_items.size(); i++) { m_w += m_dock->m_items[i]->getMaxWidth(); } m_h = m_dock->m_bigIconSize; } else { // Vertical // calculate w and h for (unsigned int i = 0; i < m_dock->m_items.size(); i++) m_h += m_dock->m_items[i]->getMaxHeight(); m_w = m_dock->m_bigIconSize; } if (m_dock->m_orientation == Qt::Horizontal && m_h != old_h) { m_buffer.reset(new QPixmap(dw, m_h)); m_background.reset(new KPixmap(*m_buffer)); // update background updateBackgroundImage(); } else if (m_dock->m_orientation == Qt::Vertical && m_w != old_w) { m_buffer.reset(new QPixmap(m_w, dh)); m_background.reset(new KPixmap(*m_buffer)); // update background updateBackgroundImage(); } int x = (dw - m_w) / 2; int y = (dh - m_h) / 2; // set strut of the dock and move it switch(m_dock->m_position) { case LEFT: if (m_dock->m_isAutohide) { KWin::setExtendedStrut(m_dock->winId(), 1, 0, dh, 0, 0, 0, 0, 0, 0, 0, 0, 0); KSmoothDock::setDesktopIconsArea(0, 0, dw, dh); } else { KWin::setExtendedStrut(m_dock->winId(), m_w, 0, dh, 0, 0, 0, 0, 0, 0, 0, 0, 0); KSmoothDock::setDesktopIconsArea(m_w, 0, dw - m_w, dh); } m_dock->move(0, y); break; case RIGHT: if (m_dock->m_isAutohide) { KWin::setExtendedStrut(m_dock->winId(), 0, 0, 0, 1, 0, dh, 0, 0, 0, 0, 0, 0); KSmoothDock::setDesktopIconsArea(0, 0, dw, dh); } else { KWin::setExtendedStrut(m_dock->winId(), 0, 0, 0, m_w, 0, dh, 0, 0, 0, 0, 0, 0); KSmoothDock::setDesktopIconsArea(0, 0, dw - m_w, dh); } m_dock->move(dw - m_w, y); break; case TOP: if (m_dock->m_isAutohide) { KWin::setExtendedStrut(m_dock->winId(), 0, 0, 0, 0, 0, 0, 1, 0, dw, 0, 0, 0); KSmoothDock::setDesktopIconsArea(0, 0, dw, dh); } else { KWin::setExtendedStrut(m_dock->winId(), 0, 0, 0, 0, 0, 0, m_h, 0, dw, 0, 0, 0); KSmoothDock::setDesktopIconsArea(0, m_h, dw, dh - m_h); } m_dock->move(x, 0); break; case BOTTOM: if (m_dock->m_isAutohide) { KWin::setExtendedStrut(m_dock->winId(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, dw); KSmoothDock::setDesktopIconsArea(0, 0, dw, dh); } else { KWin::setExtendedStrut(m_dock->winId(), 0, 0, 0, 0, 0, 0, 0, 0, 0, m_h, 0, dw); KSmoothDock::setDesktopIconsArea(0, 0, dw, dh - m_h); } m_dock->move(x, dh - m_h); break; default: break; } // resize the dock m_dock->resize(m_w, m_h); if (m_dock->m_isAutohide && m_isHidden) { setMaskOn(true); } else { setMaskOn(false); } m_dock->repaint();}/** * Update the background */void NormalZoomState::updateBackground() { updateBackgroundImage(); m_dock->repaint();}/** * Paint event handler */void NormalZoomState::paintEvent(QPaintEvent* e) { int x = 0; int y = 0; int w = 0; int h = 0; unsigned int i = 0; if (m_dock->m_isAutohide && m_isHidden) { if (!m_maskOn) { setMaskOn(true); } } else { if (m_maskOn) { setMaskOn(false); } if (m_dock->m_orientation == Qt::Horizontal) { // draw the background for (i = 0; i < m_firstIndexToUpdate; i++) x += m_dock->m_items[i]->getMaxWidth(); for (i = m_firstIndexToUpdate; i <= m_lastIndexToUpdate; i++) w += m_dock->m_items[i]->getMaxWidth(); w += 3; // fix the drawing bug bitBlt(m_buffer.get(), x, 0, m_background.get(), x, 0, w, m_h); // draw the items int x_item = x; for (i = m_firstIndexToUpdate; i <= m_lastIndexToUpdate; i++) { DockItem* item = m_dock->m_items[i]; int dx = (item->getMaxWidth() - item->getWidth(m_itemsSize[i])) / 2; int dy = (item->getMaxHeight() - item->getHeight(m_itemsSize[i])) / 2; if ((int)i == m_clickedLauncherIndex) { // launcher clicked acknowlegement Launcher* l = dynamic_cast<Launcher*>(item); l->drawAcknowledgement(*m_buffer, x_item + dx, dy, m_itemsSize[i]); } else { item->draw(*m_buffer, x_item + dx, dy, m_itemsSize[i]); } x_item += item->getMaxWidth(); } // update the dock bitBlt(m_dock, x, 0, m_buffer.get(), x, 0, w, m_h); } else { // Vertical // draw the background for (i = 0; i < m_firstIndexToUpdate; i++) y += m_dock->m_items[i]->getMaxHeight(); for (i = m_firstIndexToUpdate; i <= m_lastIndexToUpdate; i++) h += m_dock->m_items[i]->getMaxHeight(); h += 3; // fix the drawing bug bitBlt(m_buffer.get(), 0, y, m_background.get(), 0, y, m_w, h); // draw the items int y_item = y; for (i = m_firstIndexToUpdate; i <= m_lastIndexToUpdate; i++) { DockItem* item = m_dock->m_items[i]; int dx = (item->getMaxWidth() - item->getWidth(m_itemsSize[i])) / 2; int dy = (item->getMaxHeight() - item->getHeight(m_itemsSize[i])) / 2; if ((int)i == m_clickedLauncherIndex) { // launcher clicked acknowlegement Launcher* l = dynamic_cast<Launcher*>(item); l->drawAcknowledgement(*m_buffer, dx, y_item + dy, m_itemsSize[i]); } else { item->draw(*m_buffer, dx, y_item + dy, m_itemsSize[i]); } y_item += item->getMaxHeight(); } // update the dock bitBlt(m_dock, 0, y, m_buffer.get(), 0, y, m_w, h); } } }/** * Mouse pressed event handler */void NormalZoomState::mousePressEvent(QMouseEvent* e) { // find the m_dock item's index int i = findItemIndex(e->x(), e->y()); // call the item's mouse event handler m_dock->m_items[i]->mousePressEvent(e); // launcher acknowledgement if (e->button() == Qt::LeftButton) { Launcher l; if (typeid(*m_dock->m_items[i]) == typeid(l)) { m_clickedLauncherIndex = i; QTimer::singleShot(500, this, SLOT(stopLauncherAcknowledgement())); m_dock->repaint(); Launcher* launcher = dynamic_cast<Launcher*>(m_dock->m_items[i]); if (launcher->getCommand().compare("SHOW_DESKTOP") == 0) { // Show Desktop button updateAfterShowingDesktop(); } } }}/** * Mouse moved event handler */void NormalZoomState::mouseMoveEvent(QMouseEvent* e) { // find the m_dock item's index int i = findItemIndex(e->x(), e->y()); if (m_lastFocusedItemIndex != i) { // show tooltip if (m_dock->m_showTooltip) { m_dock->m_tooltip.setText(m_dock->m_items[i]->getDescription()); int x = m_dock->x(); int y = m_dock->y(); if (m_dock->m_orientation == Qt::Horizontal) { for (int j = 0; j < i; j++) { x += m_dock->m_items[j]->getMaxWidth(); } x = x + m_dock->m_items[i]->getMaxWidth() / 2 - m_dock->m_tooltip.width() / 2; if (m_dock->m_position == TOP) y = y + m_dock->height() + TOOLTIP_SPACE; else // BOTTOM y = y - m_dock->m_tooltip.height() - TOOLTIP_SPACE; } else { // Vertical for (int j = 0; j < i; j++) { y += m_dock->m_items[j]->getMaxHeight(); } y = y + m_dock->m_items[i]->getMaxHeight() / 2 - m_dock->m_tooltip.height() / 2; if (m_dock->m_position == LEFT) x = x + m_dock->width() + TOOLTIP_SPACE; else // RIGHT x = x - m_dock->m_tooltip.width() - TOOLTIP_SPACE; } m_dock->m_tooltip.move(x, y); if (!m_dock->m_tooltip.isShown()) m_dock->m_tooltip.show(); } // zoom items m_itemsSizeIncrement[i] = 1; if (m_lastFocusedItemIndex >= 0 && m_lastFocusedItemIndex < (int) m_dock->m_items.size()) m_itemsSizeIncrement[m_lastFocusedItemIndex] = -1; if (!m_timer->isActive()) m_timer->start(32 - m_dock->m_NzZoomSpeed); m_lastFocusedItemIndex = i; }}/** * Enter event handler */void NormalZoomState::enterEvent(QEvent* e) { if (m_dock->m_isAutohide && m_isHidden) { m_isHidden = false; updateBackgroundImage(); m_dock->setDockAbove(); updateLayout(); }}/** * Leave event handler */void NormalZoomState::leaveEvent(QEvent* e) { if (m_dock->m_tooltip.isShown()) m_dock->m_tooltip.hide(); if (m_dock->m_isAutohide && !m_isHidden) { m_isHidden = true; updateBackgroundImage(); m_dock->setDockBelow(); updateLayout(); } else { m_itemsSizeIncrement[m_lastFocusedItemIndex] = -1; m_lastFocusedItemIndex = -1; if (!m_timer->isActive()) m_timer->start((32 - m_dock->m_NzZoomSpeed)); }}/** * Update a specific item * @TODO: fix and use the effient method (at the moment it does not work properly when the dock is vertical) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -