📄 ksmoothdock.cpp
字号:
if (m_position == TOP || m_position == BOTTOM) { m_orientation = Horizontal; } else { m_orientation = Vertical; } // correct the icon sizes if needed if (m_NzSmallIconSize > m_NzBigIconSize || m_PzSmallIconSize > m_PzBigIconSize) { m_NzSmallIconSize = NZ_DEFAULT_SMALL_SIZE; m_NzBigIconSize = NZ_DEFAULT_BIG_SIZE; m_PzSmallIconSize = PZ_DEFAULT_SMALL_SIZE; m_PzBigIconSize = PZ_DEFAULT_BIG_SIZE; } if (!m_showTaskbar) { m_showNotification = 0; } if (first_run) { saveConfig(); }}/** * Save configuration data */void KSmoothDock::saveConfig() { KConfig* config = KGlobal::config(); config->setGroup("ksmoothdock"); config->writeEntry("ZoomMode", m_zoomMode); config->writeEntry("NormalZoomSpeed", m_NzZoomSpeed); config->writeEntry("ParabolicZoomSpeed", m_PzZoomSpeed); config->writeEntry("ShowPager", m_showPager); config->writeEntry("ShowTaskbar", m_showTaskbar); config->writeEntry("ShowWindowsFromAllDesktops", m_showWindowsAllDesktops); config->writeEntry("ShowClock", m_showClock); config->writeEntry("ShowNotification", m_showNotification); config->writeEntry("ShowBorders", m_showBorders); config->writeEntry("BorderColor", m_borderColor.name()); config->writeEntry("PanelPosition", m_position); config->writeEntry("SmallIconSizeNormalZoom", m_NzSmallIconSize); config->writeEntry("BigIconSizeNormalZoom", m_NzBigIconSize); config->writeEntry("BaseIconSizeNormalZoom", m_NzBaseIconSize); config->writeEntry("SmallIconSizeParabolicZoom", m_PzSmallIconSize); config->writeEntry("BigIconSizeParabolicZoom", m_PzBigIconSize); config->writeEntry("BaseIconSizeParabolicZoom", m_PzBaseIconSize); config->writeEntry("Autohide", m_isAutohide); config->writeEntry("DockOpacity", m_dockOpacity); config->writeEntry("BackgroundColor", m_backgroundColor.name()); config->writeEntry("SeparatorColor", m_separatorColor.name()); config->writeEntry("ScreenWidth", m_screenWidth); config->writeEntry("ActiveDesktopColor", m_activeDesktopColor.name()); config->writeEntry("InactiveDesktopColor", m_inactiveDesktopColor.name()); config->writeEntry("ShowTooltip", m_showTooltip); config->writeEntry("TooltipFontFace", m_tooltipFontFace); config->writeEntry("TooltipFontSize", m_tooltipFontSize); config->writeEntry("TooltipFontItalic", m_tooltipFontIsItalic); config->writeEntry("TooltipFontBold", m_tooltipFontIsBold); config->writeEntry("TooltipFontColor", m_tooltipFontColor.name()); config->writeEntry("TooltipFontBgColor", m_tooltipBackgroundColor.name()); config->writeEntry("Use24HourClock", m_use24HourClock); config->writeEntry("ClockFontColor", m_clockFontColor.name()); config->writeEntry("ClockFontFace", m_clockFontFace); config->writeEntry("ClockFontSize", m_clockFontSize); config->writeEntry("ClockFontItalic", m_clockFontIsItalic); config->writeEntry("ClockFontBold", m_clockFontIsBold); config->sync();}/** * Initiate variables */void KSmoothDock::initVariables() { // init path m_dataPath = locateLocal("data", "ksmoothdock"); m_launchersPath = m_dataPath + QString("/menu/"); // init icon sizes if (m_zoomMode == NORMAL_ZOOM) { m_baseIconSize = m_NzBaseIconSize; m_smallIconSize = m_NzSmallIconSize; m_bigIconSize = m_NzBigIconSize; } else { m_baseIconSize = m_PzBaseIconSize; m_smallIconSize = m_PzSmallIconSize; m_bigIconSize = m_PzBigIconSize; } // state m_normalZoomState = NULL; m_parabolicZoomState = NULL; m_buttonisedState = NULL; if (m_zoomMode == NORMAL_ZOOM) { m_normalZoomState = new NormalZoomState(this); m_state = m_normalZoomState; } else { // Parabolic m_parabolicZoomState = new ParabolicZoomState(this); m_state = m_parabolicZoomState; } // tooltip if (m_showTooltip) { m_tooltip.setFontFace(m_tooltipFontFace); m_tooltip.setFontSize(m_tooltipFontSize); m_tooltip.setFontBold(m_tooltipFontIsBold); m_tooltip.setFontItalic(m_tooltipFontIsItalic); m_tooltip.setFontColor(m_tooltipFontColor); m_tooltip.setBackgroundColor(m_tooltipBackgroundColor); } m_itemIndexInitialiser = 0; m_aboutDialog.reset(new AboutDialog()); m_configDialog.reset(new ConfigDialog(this)); m_launcherConfigDialog.reset(new LauncherConfigDialog()); connect(m_launcherConfigDialog.get(), SIGNAL(updated()), this, SLOT(updateLaunchers())); m_wallpaperManager = new WallpaperManager(KWin::numberOfDesktops()); connect(m_wallpaperManager, SIGNAL(wallpaperLoaded()), this, SLOT(updateBackground())); m_rootPix.reset(new KRootPixmap(this)); m_rootPix->setCustomPainting(true); connect(m_rootPix.get(), SIGNAL(backgroundUpdated(const QPixmap&)), this, SLOT(updateBackground(const QPixmap&))); m_rootPix->start();// else// m_state = new HiddenState(); connect(&m_windowManager, SIGNAL(currentDesktopChanged(int)), this, SLOT(currentDesktopChanged(int))); connect(&m_windowManager, SIGNAL(windowAdded (WId)), this, SLOT(windowAdded (WId))); connect(&m_windowManager, SIGNAL(windowRemoved (WId)), this, SLOT(windowRemoved (WId))); connect(&m_windowManager, SIGNAL(windowChanged(WId, unsigned int)), this, SLOT(windowChanged(WId, unsigned int))); connect(&m_windowManager, SIGNAL(activeWindowChanged(WId)), this, SLOT(activeWindowChanged(WId))); }/** * Load quick launchers */void KSmoothDock::loadLaunchers(bool reset) { m_items.clear(); QDir home_dir = QDir::home(); if (reset) { if (home_dir.exists(m_launchersPath)) { // delete the launchers directory QDir dir(m_launchersPath); QStringList file_list = dir.entryList("*"); for (QStringList::Iterator it = file_list.begin(); it != file_list.end(); it++) { if ((*it) && (*it != ".") && (*it != "..")) { dir.remove(*it); } } home_dir.rmdir(m_launchersPath); home_dir.rmdir(m_dataPath); } createDefaultLaunchers(); } else { if (home_dir.exists(m_launchersPath)) { // if the launchers directory exists QDir dir(m_launchersPath); QStringList file_list = dir.entryList("*"); for (QStringList::Iterator it = file_list.begin(); it != file_list.end(); it++) { if ((*it) && (*it != ".") && (*it != "..")) { m_items.push_back(new Launcher(this, m_itemIndexInitialiser++, m_launchersPath + (*it), m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation)); } } } else { // otherwise create default quick launchers createDefaultLaunchers(); } } //std::cout << "Loaded " << m_items.size() << " launchers" << std::endl;}/** * Create default quick launchers */ void KSmoothDock::createDefaultLaunchers() { QDir home_dir = QDir::home(); if (!home_dir.mkdir(m_dataPath) || !home_dir.mkdir(m_launchersPath)) { KMessageBox::information(this, QString("Could not create data folder: ") + m_launchersPath); return; } Launcher* item1 = new Launcher(this, m_itemIndexInitialiser++, "Start Applications", ON_ALL_DESKTOPS, "kmenu", m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation, "dcop kicker kicker popupKMenu 0"); item1->saveToFile(m_launchersPath + "0 - KMenu"); m_items.push_back(item1); Launcher* item2 = new Launcher(this, m_itemIndexInitialiser++, "Show Desktop", ON_ALL_DESKTOPS, "desktop", m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation, "SHOW_DESKTOP"); item2->saveToFile(m_launchersPath + "1 - show desktop"); m_items.push_back(item2); Launcher* item3 = new Launcher(this, m_itemIndexInitialiser++, "Konsole", ON_ALL_DESKTOPS, "konsole", m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation, "konsole"); item3->saveToFile(m_launchersPath + "2 - konsole"); m_items.push_back(item3); Launcher* item4 = new Launcher(this, m_itemIndexInitialiser++, "Home Directory", ON_ALL_DESKTOPS, "kfm_home", m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation, "kfmclient openProfile filemanagement"); item4->saveToFile(m_launchersPath + "3 - home"); m_items.push_back(item4); Launcher* item5 = new Launcher(this, m_itemIndexInitialiser++, "Web Browser", ON_ALL_DESKTOPS, "package_network", m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation, "konqueror --profile webbrowsing"); item5->saveToFile(m_launchersPath + "4 - konqueror"); m_items.push_back(item5); Launcher* item6 = new Launcher(this, m_itemIndexInitialiser++, "Control Center", ON_ALL_DESKTOPS, "kcontrol", m_baseIconSize, m_smallIconSize, m_bigIconSize, m_orientation, "kcontrol"); item6->saveToFile(m_launchersPath + "5 - control center"); m_items.push_back(item6);}/** * Initiate the pager */void KSmoothDock::initPager() { if (m_showPager) { int num_desks = KWin::numberOfDesktops(); for (int i = 1; i <= num_desks; i++) { DesktopSelector* item = new DesktopSelector(this, m_itemIndexInitialiser++, "Desktop " + QString::number(i), ON_ALL_DESKTOPS, m_wallpaperManager->getWallpaper(i), m_smallIconSize, m_bigIconSize, m_orientation, i, m_wallpaperManager); m_items.push_back(item); connect(m_wallpaperManager, SIGNAL(wallpaperLoaded()), item, SLOT(updateIcon())); } } else if (m_showTaskbar) { // Add a seperator between the launchers and the taskbar Separator* item = new Separator(this, m_itemIndexInitialiser++, ON_ALL_DESKTOPS, m_smallIconSize, m_bigIconSize, 0.0, m_orientation); m_items.push_back(item); }}/** * Load running tasks */void KSmoothDock::loadTasks() { if (m_showTaskbar) { for (QValueList<WId>::ConstIterator it = m_windowManager.windows().begin(); it != m_windowManager.windows().end(); it++) { if (m_windowManager.hasWId(*it)) { addTask(*it); } } } // std::cout << "Loaded " << m_items.size() << " launchers and tasks" << std::endl;}/** * Add a task */void KSmoothDock::addTask(WId id, bool checkPosition) { QPixmap pix = KWin::icon(id, m_baseIconSize, m_baseIconSize); KWin::WindowInfo info(id, 0, 0); QString name = info.name(); if (!m_showWindowsAllDesktops) { if (!info.onAllDesktops() && info.desktop() != KWin::currentDesktop()) { return; } } NET::WindowType type = info.windowType(0xffff); if (type == NET::Normal || type == NET::Dialog || type == NET::Unknown || type == NET::Override) if ((info.state() & NET::SkipTaskbar) == 0) if (name.compare("XMMS Playlist") != 0 && name.compare("XMMS Equalizer") != 0) { Task* t = new Task(this, m_itemIndexInitialiser++, name, info.desktop(), pix, m_smallIconSize, m_bigIconSize, m_orientation, id); if (checkPosition && m_showClock) { m_items.insert(m_items.end() - 1, t); } else m_items.push_back(t); }}/** * Init the clock */void KSmoothDock::initClock() { if (m_showClock) { Clock* c = new Clock(this, m_itemIndexInitialiser++, "", ON_ALL_DESKTOPS, m_smallIconSize, m_bigIconSize, 2.0, m_orientation); c->set24HourClock(m_use24HourClock); c->setFontFace(m_clockFontFace); c->setFontSize(m_clockFontSize); c->setFontBold(m_clockFontIsBold); c->setFontItalic(m_clockFontIsItalic); c->setFontColor(m_clockFontColor); m_items.push_back(c); }}/** * Update layout */void KSmoothDock::updateLayout(bool reset) { m_state->updateLayout(reset); if (reset && m_showTooltip) { m_tooltip.hide(); }}/** * Set dock above all applications */void KSmoothDock::setDockAbove() { KWin::setState(winId(), NET::KeepAbove);}/** * Set dock below all applications */void KSmoothDock::setDockBelow() { KWin::setState(winId(), NET::KeepBelow); KWin::lowerWindow(winId());}/** * Check kicker position to avoid collision */void KSmoothDock::checkKickerPosition() { DCOPClient *client = KApplication::dcopClient(); if (!client->isAttached()) { client->attach(); client->registerAs("KSmoothDock"); } QByteArray data, replyData; QCString replyType; client->call("kicker", "Panel", "panelPosition()", data, replyType, replyData ); QDataStream reply(replyData, IO_ReadOnly); if (replyType == "int") { int result; PanelPosition kicker_pos; reply >> result; //cout << "the result is: " << result << endl; switch(result) { case 0: kicker_pos = LEFT; break; case 1: kicker_pos = RIGHT; break; case 2: kicker_pos = TOP; break; case 3: kicker_pos = BOTTOM; break; } if (kicker_pos == m_position) { KMessageBox::information(this, i18n("KSmoothDock and kicker have the same position on the screen and hence can overlap each other visually. Please move one of these to another position."), i18n("KSmoothDock and kicker"), "ShowAgainCheckKickerPosition"); } }}#include "ksmoothdock.moc"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -