kexi

kexidbutils.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2006-2007 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 <kexidb/utils.h>
00027 #include <formeditor/widgetlibrary.h>
00028 #include <kexiutils/utils.h>
00029 #include "../kexiformpart.h"
00030 #include <widget/utils/kexicontextmenuutils.h>
00031 
00032 
00033 QColor lighterGrayBackgroundColor(const QPalette& palette)
00034 {
00035     return KexiUtils::blendedColors(palette.active().background(), palette.active().base(), 1, 2);
00036 }
00037 
00038 //-------
00039 
00040 KexiDBWidgetContextMenuExtender::KexiDBWidgetContextMenuExtender( QObject* parent, KexiDataItemInterface* iface )
00041  : QObject(parent)
00042  , m_iface(iface)
00043  , m_contextMenuHasTitle(false)
00044 {
00045 }
00046 
00047 KexiDBWidgetContextMenuExtender::~KexiDBWidgetContextMenuExtender()
00048 {
00049 }
00050 
00051 void KexiDBWidgetContextMenuExtender::createTitle(QPopupMenu *menu)
00052 {
00053     if (!menu)
00054         return;
00055     m_contextMenu = menu;
00056     KPopupTitle *titleItem = new KPopupTitle();
00057     const int id = m_contextMenu->insertItem(titleItem, -1, 0);
00058     m_contextMenu->setItemEnabled(id, false);
00059     QString icon;
00060     if (dynamic_cast<QWidget*>(m_iface))
00061         icon = KexiFormPart::library()->iconName(dynamic_cast<QWidget*>(m_iface)->className());
00062 
00063     m_contextMenuHasTitle = m_iface->columnInfo() ?
00064         KexiContextMenuUtils::updateTitle(m_contextMenu, 
00065             m_iface->columnInfo()->captionOrAliasOrName(), 
00066             KexiDB::simplifiedTypeName(*m_iface->columnInfo()->field), icon)
00067         : false;
00068 
00069     if (!m_contextMenuHasTitle)
00070         m_contextMenu->removeItem(id);
00071     updatePopupMenuActions();
00072 }
00073 
00074 void KexiDBWidgetContextMenuExtender::updatePopupMenuActions()
00075 {
00076     if (m_contextMenu) {
00077         enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; //from qlineedit.h
00078         const bool readOnly = m_iface->isReadOnly();
00079         const int id = m_contextMenu->idAt(m_contextMenuHasTitle ? 1 : 0);
00080 
00082         m_contextMenu->removeItem(id-(int)IdRedo);
00083 
00084         // update cut/copy/paste
00085         m_contextMenu->setItemEnabled(id-(int)IdCut, !readOnly);
00086         m_contextMenu->setItemEnabled(id-(int)IdPaste, !readOnly);
00087         m_contextMenu->setItemEnabled(id-(int)IdClear, !readOnly);
00088     }
00089 }
00090 
00091 //------------------
00092 
00093 KexiSubwidgetInterface::KexiSubwidgetInterface()
00094 {
00095 }
00096 
00097 KexiSubwidgetInterface::~KexiSubwidgetInterface()
00098 {
00099 }
KDE Home | KDE Accessibility Home | Description of Access Keys