kexidbutils.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006-2007 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexidbutils.h"
21
22#include <tdepopupmenu.h>
23#include <kiconloader.h>
24
25#include <kexidb/queryschema.h>
26#include <kexidb/utils.h>
27#include <formeditor/widgetlibrary.h>
28#include <kexiutils/utils.h>
29#include "../kexiformpart.h"
30#include <widget/utils/kexicontextmenuutils.h>
31
32
33TQColor lighterGrayBackgroundColor(const TQPalette& palette)
34{
35 return KexiUtils::blendedColors(palette.active().background(), palette.active().base(), 1, 2);
36}
37
38//-------
39
40KexiDBWidgetContextMenuExtender::KexiDBWidgetContextMenuExtender( TQObject* parent, KexiDataItemInterface* iface )
41 : TQObject(parent)
42 , m_iface(iface)
43 , m_contextMenuHasTitle(false)
44{
45}
46
47KexiDBWidgetContextMenuExtender::~KexiDBWidgetContextMenuExtender()
48{
49}
50
52{
53 if (!menu)
54 return;
55 m_contextMenu = menu;
56 TDEPopupTitle *titleItem = new TDEPopupTitle();
57 const int id = m_contextMenu->insertItem(titleItem, -1, 0);
58 m_contextMenu->setItemEnabled(id, false);
59 TQString icon;
60 if (dynamic_cast<TQWidget*>(m_iface))
61 icon = KexiFormPart::library()->iconName(dynamic_cast<TQWidget*>(m_iface)->className());
62
65 m_iface->columnInfo()->captionOrAliasOrName(),
66 KexiDB::simplifiedTypeName(*m_iface->columnInfo()->field), icon)
67 : false;
68
70 m_contextMenu->removeItem(id);
72}
73
75{
76 if (m_contextMenu) {
77 enum { IdUndo, IdRedo, IdSep1, IdCut, IdCopy, IdPaste, IdClear, IdSep2, IdSelectAll }; //from qlineedit.h
78 const bool readOnly = m_iface->isReadOnly();
79 const int id = m_contextMenu->idAt(m_contextMenuHasTitle ? 1 : 0);
80
82 m_contextMenu->removeItem(id-(int)IdRedo);
83
84 // update cut/copy/paste
85 m_contextMenu->setItemEnabled(id-(int)IdCut, !readOnly);
86 m_contextMenu->setItemEnabled(id-(int)IdPaste, !readOnly);
87 m_contextMenu->setItemEnabled(id-(int)IdClear, !readOnly);
88 }
89}
90
91//------------------
92
93KexiSubwidgetInterface::KexiSubwidgetInterface()
94{
95}
96
97KexiSubwidgetInterface::~KexiSubwidgetInterface()
98{
99}
static bool updateTitle(TQPopupMenu *menu, const TQString &objectName, const TQString &objectTypeName, const TQString &iconName)
bool m_contextMenuHasTitle
true if TDEPopupTitle has been added to the context menu.
Definition kexidbutils.h:53
void updatePopupMenuActions()
Enables or disables context menu actions that can modify the value.
void createTitle(TQPopupMenu *menu)
Creates title for context menu menu.
TQString captionOrAliasOrName() const
Definition queryschema.h:65
An interface for declaring widgets to be data-aware.
virtual bool isReadOnly() const
virtual KexiDB::QueryColumnInfo * columnInfo() const =0
static KFormDesigner::WidgetLibrary * library()
KEXI_DB_EXPORT TQString simplifiedTypeName(const Field &field)
KEXIUTILS_EXPORT TQColor blendedColors(const TQColor &c1, const TQColor &c2, int factor1=1, int factor2=1)