kexi

kexidbutils.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexidbutils.h"
00021 
00022 #include <kpopupmenu.h>
00023 #include <kiconloader.h>
00024 
00025 #include <kexidb/queryschema.h>
00026 #include <formeditor/widgetlibrary.h>
00027 #include <kexiutils/utils.h>
00028 #include "../kexiformpart.h"
00029 #include <widget/utils/kexiimagecontextmenu.h>
00030 
00031 QColor lighterGrayBackgroundColor(const QPalette& palette)
00032 {
00033     return KexiUtils::blendedColors(palette.active().background(), palette.active().base(), 1, 2);
00034 }
00035 
00036 //-------
00037 
00038 KexiDBWidgetContextMenuExtender::KexiDBWidgetContextMenuExtender( QObject* parent, KexiDataItemInterface* iface )
00039  : QObject(parent)
00040  , m_iface(iface)
00041  , m_contextMenuHasTitle(false)
00042 {
00043 }
00044 
00045 KexiDBWidgetContextMenuExtender::~KexiDBWidgetContextMenuExtender()
00046 {
00047 }
00048 
00049 void KexiDBWidgetContextMenuExtender::createTitle(QPopupMenu *menu)
00050 {
00051     if (!menu)
00052         return;
00053     m_contextMenu = menu;
00054     KPopupTitle *titleItem = new KPopupTitle();
00055     const int id = m_contextMenu->insertItem(titleItem, -1, 0);
00056     m_contextMenu->setItemEnabled(id, false);
00057     QString icon;
00058     if (dynamic_cast<QWidget*>(m_iface))
00059         icon = KexiFormPart::library()->iconName(dynamic_cast<QWidget*>(m_iface)->className());
00060 
00061     m_contextMenuHasTitle = m_iface->columnInfo() ?
00062         KexiImageContextMenu::updateTitle(m_contextMenu, m_iface->columnInfo()->captionOrAliasOrName(), icon)
00063         : false;
00064 
00065     if (!m_contextMenuHasTitle)
00066         m_contextMenu->removeItem(id);
00067     updatePopupMenuActions();
00068 }
00069 
00070 void KexiDBWidgetContextMenuExtender::updatePopupMenuActions()
00071 {
00072     if (m_contextMenu) {
00073         enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; //from qlineedit.h
00074         const bool readOnly = m_iface->isReadOnly();
00075         const int id = m_contextMenu->idAt(m_contextMenuHasTitle ? 1 : 0);
00076 
00078         m_contextMenu->removeItem(id-(int)IdRedo);
00079 
00080         // update cut/copy/paste
00081         m_contextMenu->setItemEnabled(id-(int)IdCut, !readOnly);
00082         m_contextMenu->setItemEnabled(id-(int)IdPaste, !readOnly);
00083         m_contextMenu->setItemEnabled(id-(int)IdClear, !readOnly);
00084     }
00085 }
00086 
00087 //------------------
00088 
00089 KexiSubwidgetInterface::KexiSubwidgetInterface()
00090 {
00091 }
00092 
00093 KexiSubwidgetInterface::~KexiSubwidgetInterface()
00094 {
00095 }
KDE Home | KDE Accessibility Home | Description of Access Keys