Commit a9b73774 authored by Peter Simonsson's avatar Peter Simonsson
Browse files

Clean up the start up widget code...

* Convert *.ui files to the Qt4 version
* Remove the label above the detail pane
* remove old initDoc code that isn't used anymore
* Use KUrl instead of QString to pass around the urls

svn path=/trunk/koffice/; revision=546610
parent f08033c2
......@@ -48,7 +48,6 @@
#include <KoQueryTrader.h>
#include <KoStore.h>
#include <KoStoreDevice.h>
#include <KoTemplateChooseDia.h>
#include <KoApplication.h>
// Local
......@@ -180,65 +179,20 @@ DCOPObject *KisDoc::dcopObject()
return m_dcop;
}
bool KisDoc::initDoc(InitDocFlags flags, QWidget* parentWidget)
{
if (!init())
return false;
bool ok = false;
QString file;
KoTemplateChooseDia::DialogType dlgtype;
if (flags != KoDocument::InitDocFileNew) {
dlgtype = KoTemplateChooseDia::Everything;
} else {
dlgtype = KoTemplateChooseDia::OnlyTemplates;
}
KoTemplateChooseDia::ReturnType ret =
KoTemplateChooseDia::choose(KisFactory::instance(),
file,
dlgtype,
"krita_template",
parentWidget);
setUndo(false);
if (ret == KoTemplateChooseDia::Template) {
resetURL();
ok = loadNativeFormat( file );
setEmpty();
ok = true;
} else if (ret == KoTemplateChooseDia::File) {
KUrl url( file );
ok = openURL(url);
} else if (ret == KoTemplateChooseDia::Empty) {
setEmpty();
ok = true;
}
setModified(false);
KisConfig cfg;
setUndo(cfg.undoEnabled());
return ok;
}
void KisDoc::openExistingFile(const QString& file)
void KisDoc::openExistingFile(const KUrl& url)
{
setUndo(false);
KoDocument::openExistingFile(file);
KoDocument::openExistingFile(url);
setUndo(true);
}
void KisDoc::openTemplate(const QString& file)
void KisDoc::openTemplate(const KUrl& url)
{
setUndo(false);
KoDocument::openTemplate(file);
KoDocument::openTemplate(url);
setUndo(true);
}
......
......@@ -63,7 +63,6 @@ public:
virtual bool completeLoading(KoStore *store);
virtual bool completeSaving(KoStore*);
virtual DCOPObject* dcopObject();
virtual bool initDoc(InitDocFlags flags, QWidget* parentWidget=0);
virtual bool loadOasis( const QDomDocument&, KoOasisStyles&, const QDomDocument&, KoStore* );
virtual bool saveOasis( KoStore*, KoXmlWriter* );
virtual bool loadChildren( KoStore* store);
......@@ -173,8 +172,8 @@ protected:
protected slots:
// Overide KoDocument
virtual void openExistingFile(const QString& file);
virtual void openTemplate(const QString& file);
virtual void openExistingFile(const KUrl& url);
virtual void openTemplate(const KUrl& url);
private slots:
void slotUpdate(KisImageSP img, quint32 x, quint32 y, quint32 w, quint32 h);
......
......@@ -55,18 +55,20 @@ set(kofficecore_LIB_SRCS
KoDetailsPane.cpp
KoOasisLoadingContext.cpp
KoRect.cpp
KoDocumentInfoPropsPage.cpp )
KoDocumentInfoPropsPage.cpp
KoTemplatesPane.cpp
KoRecentDocumentsPane.cpp )
kde4_automoc(${kofficecore_LIB_SRCS})
kde4_add_ui3_files(kofficecore_LIB_SRCS
# koDocumentInfoUserMetadataWidget.ui
koDetailsPaneBase.ui
koOpenPaneBase.ui )
#kde4_add_ui3_files(kofficecore_LIB_SRCS
# koDocumentInfoUserMetadataWidget.ui )
kde4_add_ui_files( kofficecore_LIB_SRCS
koDocumentInfoAboutWidget.ui
koDocumentInfoAuthorWidget.ui )
koDocumentInfoAuthorWidget.ui
koOpenPaneBase.ui
koDetailsPaneBase.ui )
kde4_add_dcop_skels(kofficecore_LIB_SRCS
KoApplicationIface.h
......
......@@ -22,16 +22,12 @@
#include <QLabel>
#include <QFile>
#include <QImage>
#include <q3header.h>
#include <QRect>
#include <QBrush>
#include <QPainter>
#include <q3simplerichtext.h>
#include <QEvent>
#include <QSplitter>
//Added by qt3to4:
#include <QPixmap>
#include <Q3ValueList>
#include <kinstance.h>
#include <klocale.h>
......@@ -47,200 +43,65 @@
#include "KoTemplates.h"
class KoFileListItem : public K3ListViewItem
{
public:
KoFileListItem(K3ListView* listView, Q3ListViewItem* after, const QString& filename,
const QString& fullPath, KFileItem* fileItem)
: K3ListViewItem(listView, after, filename, fullPath), m_fileItem(fileItem)
{
}
~KoFileListItem()
{
delete m_fileItem;
}
KFileItem* fileItem() const
{
return m_fileItem;
}
private:
KFileItem* m_fileItem;
};
////////////////////////////////////
// class KoDetailsPane
///////////////////////////////////
class KoTemplatesPanePrivate
class KoDetailsPanePrivate
{
public:
KoTemplatesPanePrivate()
: m_instance(0), m_selected(false)
KoDetailsPanePrivate() :
m_instance(0)
{
}
KInstance* m_instance;
bool m_selected;
QString m_alwaysUseTemplate;
};
KoTemplatesPane::KoTemplatesPane(QWidget* parent, KInstance* instance,
KoTemplateGroup *group, KoTemplate* /*defaultTemplate*/)
: KoDetailsPaneBase(parent, "TemplatesPane")
KoDetailsPane::KoDetailsPane(QWidget* parent, KInstance* _instance, const QString& header)
: QWidget(parent), Ui_KoDetailsPaneBase()
{
d = new KoTemplatesPanePrivate;
d->m_instance = instance;
d = new KoDetailsPanePrivate;
d->m_instance = _instance;
setupUi(this);
m_previewLabel->installEventFilter(this);
m_documentList->installEventFilter(this);
setFocusProxy(m_documentList);
m_documentList->setShadeSortColumn(false);
KGuiItem openGItem(i18n("Use This Template"));
m_openButton->setGuiItem(openGItem);
m_documentList->header()->hide();
KConfigGroup cfgGrp(d->m_instance->config(), "TemplateChooserDialog");
QString fullTemplateName = cfgGrp.readPathEntry("FullTemplateName");
d->m_alwaysUseTemplate = cfgGrp.readPathEntry("AlwaysUseTemplate");
connect(m_alwaysUseCheckBox, SIGNAL(clicked()), this, SLOT(alwaysUseClicked()));
m_documentList->setColumnText(0, header);
changePalette();
if(kapp) {
connect(kapp, SIGNAL(kdisplayPaletteChanged()), this, SLOT(changePalette()));
}
QString dontShow = "imperial";
if(KGlobal::locale()->measureSystem() == KLocale::Imperial) {
dontShow = "metric";
}
K3ListViewItem* selectItem = 0;
for (KoTemplate* t = group->first(); t != 0L; t = group->next()) {
if(t->isHidden() || (t->measureSystem() == dontShow))
continue;
K3ListViewItem* item = new K3ListViewItem(m_documentList, t->name(), t->description(), t->file());
QPixmap preview = t->loadPicture(instance);
QImage icon = preview.toImage();
icon = icon.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation);
icon.convertToFormat(QImage::Format_ARGB32);
icon = icon.copy((icon.width() - 64) / 2, (icon.height() - 64) / 2, 64, 64);
item->setPixmap(0, QPixmap::fromImage(icon));
item->setPixmap(2, preview);
if(d->m_alwaysUseTemplate == t->file()) {
selectItem = item;
} else if(!selectItem && (t->file() == fullTemplateName)) {
selectItem = item;
}
}
connect(m_documentList, SIGNAL(selectionChanged(Q3ListViewItem*)),
this, SLOT(selectionChanged(Q3ListViewItem*)));
this, SLOT(selectionChanged(Q3ListViewItem*)));
connect(m_documentList, SIGNAL(clicked(Q3ListViewItem*)),
this, SLOT(selectionChanged(Q3ListViewItem*)));
connect(m_documentList, SIGNAL(doubleClicked(Q3ListViewItem*, const QPoint&, int)),
this, SLOT(openTemplate(Q3ListViewItem*)));
this, SLOT(openFile(Q3ListViewItem*)));
connect(m_documentList, SIGNAL(returnPressed(Q3ListViewItem*)),
this, SLOT(openTemplate(Q3ListViewItem*)));
connect(m_openButton, SIGNAL(clicked()), this, SLOT(openTemplate()));
if(selectItem) {
m_documentList->setSelected(selectItem, true);
d->m_selected = true;
} else {
m_documentList->setSelected(m_documentList->firstChild(), true);
}
this, SLOT(openFile(Q3ListViewItem*)));
connect(m_openButton, SIGNAL(clicked()), this, SLOT(openFile()));
}
KoTemplatesPane::~KoTemplatesPane()
KoDetailsPane::~KoDetailsPane()
{
delete d;
}
void KoTemplatesPane::selectionChanged(Q3ListViewItem* item)
{
if(item) {
m_openButton->setEnabled(true);
m_alwaysUseCheckBox->setEnabled(true);
m_titleLabel->setText(item->text(0));
m_previewLabel->setPixmap(*(item->pixmap(2)));
m_detailsLabel->setHtml(item->text(1));
m_alwaysUseCheckBox->setChecked(item->text(2) == d->m_alwaysUseTemplate);
} else {
m_openButton->setEnabled(false);
m_alwaysUseCheckBox->setEnabled(false);
m_alwaysUseCheckBox->setChecked(false);
m_titleLabel->clear();
m_previewLabel->setPixmap(QPixmap());
m_detailsLabel->clear();
}
}
void KoTemplatesPane::openTemplate()
{
Q3ListViewItem* item = m_documentList->selectedItem();
openTemplate(item);
}
void KoTemplatesPane::openTemplate(Q3ListViewItem* item)
{
if(item) {
KConfigGroup cfgGrp(d->m_instance->config(), "TemplateChooserDialog");
cfgGrp.writePathEntry("FullTemplateName", item->text(2));
cfgGrp.writeEntry("LastReturnType", "Template");
cfgGrp.writeEntry("AlwaysUseTemplate", d->m_alwaysUseTemplate);
emit openTemplate(item->text(2));
}
}
void KoTemplatesPane::changePalette()
{
QPalette p = kapp ? kapp->palette() : palette();
p.setBrush(QColorGroup::Base, p.brush(QPalette::Normal, QColorGroup::Background));
p.setColor(QColorGroup::Text, p.color(QPalette::Normal, QColorGroup::Foreground));
m_detailsLabel->setPalette(p);
}
bool KoTemplatesPane::isSelected()
{
return d->m_selected;
}
void KoTemplatesPane::alwaysUseClicked()
KInstance* KoDetailsPane::instance()
{
Q3ListViewItem* item = m_documentList->selectedItem();
if(!m_alwaysUseCheckBox->isChecked()) {
KConfigGroup cfgGrp(d->m_instance->config(), "TemplateChooserDialog");
cfgGrp.writeEntry("AlwaysUseTemplate", QString());
d->m_alwaysUseTemplate = QString::null;
} else {
d->m_alwaysUseTemplate = item->text(2);
}
emit alwaysUseChanged(this, d->m_alwaysUseTemplate);
return d->m_instance;
}
void KoTemplatesPane::changeAlwaysUseTemplate(KoTemplatesPane* sender, const QString& alwaysUse)
{
if(this == sender)
return;
Q3ListViewItem* item = m_documentList->selectedItem();
// If the old always use template is selected uncheck the checkbox
if(item && (item->text(2) == d->m_alwaysUseTemplate)) {
m_alwaysUseCheckBox->setChecked(false);
}
d->m_alwaysUseTemplate = alwaysUse;
}
bool KoTemplatesPane::eventFilter(QObject* watched, QEvent* e)
bool KoDetailsPane::eventFilter(QObject* watched, QEvent* e)
{
if(watched == m_previewLabel) {
if(e->type() == QEvent::MouseButtonDblClick) {
openTemplate();
openFile();
}
}
......@@ -253,199 +114,21 @@ bool KoTemplatesPane::eventFilter(QObject* watched, QEvent* e)
return false;
}
void KoTemplatesPane::resizeSplitter(KoDetailsPaneBase* sender, const QList<int>& sizes)
void KoDetailsPane::resizeSplitter(KoDetailsPane* sender, const QList<int>& sizes)
{
if(sender == this)
return;
return;
m_splitter->setSizes(sizes);
}
class KoRecentDocumentsPanePrivate
{
public:
KoRecentDocumentsPanePrivate()
: m_previewJob(0), m_instance(0)
{
}
~KoRecentDocumentsPanePrivate()
{
if(m_previewJob)
m_previewJob->kill();
}
KIO::PreviewJob* m_previewJob;
KInstance* m_instance;
};
KoRecentDocumentsPane::KoRecentDocumentsPane(QWidget* parent, KInstance* instance)
: KoDetailsPaneBase(parent, "RecentDocsPane")
{
d = new KoRecentDocumentsPanePrivate;
d->m_instance = instance;
m_previewLabel->installEventFilter(this);
m_documentList->installEventFilter(this);
setFocusProxy(m_documentList);
KGuiItem openGItem(i18n("Open This Document"), "fileopen");
m_openButton->setGuiItem(openGItem);
m_alwaysUseCheckBox->hide();
m_documentList->header()->hide();
m_documentList->setSorting(-1); // Disable sorting
changePalette();
if(kapp) {
connect(kapp, SIGNAL(kdisplayPaletteChanged()), this, SLOT(changePalette()));
}
QString oldGroup = instance->config()->group();
instance->config()->setGroup("RecentFiles");
int i = 0;
QString value;
KFileItemList fileList;
do {
QString key = QString("File%1").arg(i);
value = instance->config()->readPathEntry(key);
if(!value.isEmpty()) {
QString path = value;
QString name;
// Support for kdelibs-3.5's new RecentFiles format: name[url]
if(path.endsWith("]")) {
int pos = path.indexOf("[");
name = path.mid(0, pos - 1);
path = path.mid(pos + 1, path.length() - pos - 2);
}
KUrl url = KUrl::fromPathOrUrl(path);
if(name.isEmpty())
name = url.fileName();
if(!url.isLocalFile() || QFile::exists(url.path())) {
KFileItem* fileItem = new KFileItem(KFileItem::Unknown, KFileItem::Unknown, url);
fileList.append(fileItem);
KoFileListItem* item = new KoFileListItem(m_documentList,
m_documentList->lastItem(), name, url.url(), fileItem);
//center all icons in 64x64 area
QImage icon = fileItem->pixmap(64).toImage();
icon.convertToFormat(QImage::Format_ARGB32);
icon = icon.copy((icon.width() - 64) / 2, (icon.height() - 64) / 2, 64, 64);
item->setPixmap(0, QPixmap::fromImage(icon));
item->setPixmap(2, fileItem->pixmap(128));
}
}
i++;
} while ( !value.isEmpty() || i<=10 );
instance->config()->setGroup( oldGroup );
connect(m_documentList, SIGNAL(selectionChanged(Q3ListViewItem*)),
this, SLOT(selectionChanged(Q3ListViewItem*)));
connect(m_documentList, SIGNAL(clicked(Q3ListViewItem*)),
this, SLOT(selectionChanged(Q3ListViewItem*)));
connect(m_documentList, SIGNAL(doubleClicked(Q3ListViewItem*, const QPoint&, int)),
this, SLOT(openFile(Q3ListViewItem*)));
connect(m_documentList, SIGNAL(returnPressed(Q3ListViewItem*)),
this, SLOT(openFile(Q3ListViewItem*)));
connect(m_openButton, SIGNAL(clicked()), this, SLOT(openFile()));
m_documentList->setSelected(m_documentList->firstChild(), true);
d->m_previewJob = KIO::filePreview(fileList, 200, 200);
connect(d->m_previewJob, SIGNAL(result(KJob*)), this, SLOT(previewResult(KJob*)));
connect(d->m_previewJob, SIGNAL(gotPreview(const KFileItem*, const QPixmap&)),
this, SLOT(updatePreview(const KFileItem*, const QPixmap&)));
}
KoRecentDocumentsPane::~KoRecentDocumentsPane()
{
delete d;
}
void KoRecentDocumentsPane::selectionChanged(Q3ListViewItem* item)
{
if(item) {
m_openButton->setEnabled(true);
m_titleLabel->setText(item->text(0));
m_previewLabel->setPixmap(*(item->pixmap(2)));
if(static_cast<KoFileListItem*>(item)->fileItem()) {
KFileItem* fileItem = static_cast<KoFileListItem*>(item)->fileItem();
QString details = "<center><table border=\"0\">";
details += i18nc("File modification date and time. %1 is date time", "<tr><td><b>Modified:</b></td><td>%1</td></tr>",
QString(fileItem->timeString(KIO::UDS_MODIFICATION_TIME)));
details += i18nc("File access date and time. %1 is date time", "<tr><td><b>Accessed:</b></td><td>%1</td></tr>",
QString(fileItem->timeString(KIO::UDS_ACCESS_TIME)));
details += "</table></center>";
m_detailsLabel->setHtml(details);
} else {
m_detailsLabel->clear();
}
} else {
m_openButton->setEnabled(false);
m_titleLabel->clear();
m_previewLabel->setPixmap(QPixmap());
m_detailsLabel->clear();
}
}
void KoRecentDocumentsPane::openFile()
void KoDetailsPane::openFile()
{
Q3ListViewItem* item = m_documentList->selectedItem();
openFile(item);
}
void KoRecentDocumentsPane::openFile(Q3ListViewItem* item)
{
KConfigGroup cfgGrp(d->m_instance->config(), "TemplateChooserDialog");
cfgGrp.writeEntry("LastReturnType", "File");
if(item)
emit openFile(item->text(1));
}
void KoRecentDocumentsPane::previewResult(KJob* job)
{
if(d->m_previewJob == job)
d->m_previewJob = 0;
}
void KoRecentDocumentsPane::updatePreview(const KFileItem* fileItem, const QPixmap& preview)
{
if(preview.isNull()) {
return;
}
Q3ListViewItemIterator it(m_documentList);
while(it.current()) {
if(it.current()->text(1) == fileItem->url().url()) {
it.current()->setPixmap(2, preview);
QImage icon = preview.toImage();
icon = icon.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation);
icon.convertToFormat(QImage::Format_ARGB32);
icon = icon.copy((icon.width() - 64) / 2, (icon.height() - 64) / 2, 64, 64);
it.current()->setPixmap(0, QPixmap::fromImage(icon));
if(it.current()->isSelected()) {
m_previewLabel->setPixmap(preview);
}
break;
}
it++;
}
}
void KoRecentDocumentsPane::changePalette()
void KoDetailsPane::changePalette()
{
QPalette p = kapp ? kapp->palette() : palette();
p.setBrush(QColorGroup::Base, p.brush(QPalette::Normal, QColorGroup::Background));
......@@ -453,29 +136,4 @@ void KoRecentDocumentsPane::changePalette()
m_detailsLabel->setPalette(p);
}
bool KoRecentDocumentsPane::eventFilter(QObject* watched, QEvent* e)
{
if(watched == m_previewLabel) {
if(e->type() == QEvent::MouseButtonDblClick) {
openFile();
}
}
if(watched == m_documentList) {
if((e->type() == QEvent::Resize) && isVisible()) {
emit splitterResized(this, m_splitter->sizes());
}
}
return false;
}
void KoRecentDocumentsPane::resizeSplitter(KoDetailsPaneBase* sender, const QList<int>& sizes)
{
if(sender ==