Example #1
0
void ContextHelp::requestItemDescriptionsDirectory()
{
	KDirSelectDialog * dlg = new KDirSelectDialog( itemLibrary()->itemDescriptionsDirectory(), true );
	if ( dlg->exec() == QDialog::Accepted )
	{
		itemLibrary()->setItemDescriptionsDirectory( dlg->url().path() );
	}
	delete dlg;
	return;
}
Example #2
0
void ContextHelp::slotSave()
{
	if ( !saveDescription( m_currentLanguage ) )
		return;
	
	setContextHelp( m_pNameLabel->text(), itemLibrary()->description( m_lastItemType, KGlobal::locale()->language() ) );
	m_pWidgetStack->raiseWidget( 0 );
}
Example #3
0
void ContextHelp::slotEdit()
{
	if ( m_lastItemType.isEmpty() )
		return;
	
	QStringList resourcePaths;
	QString currentResourcePath = itemLibrary()->itemDescriptionsDirectory();
	QString defaultResourcePath = KStandardDirs::locate( "appdata", "contexthelp/" );
	
	resourcePaths << currentResourcePath;
	if ( currentResourcePath != defaultResourcePath )
		resourcePaths << defaultResourcePath;
	
	m_pEditor->setResourcePaths( resourcePaths );
	QString description = itemLibrary()->description( m_lastItemType, m_currentLanguage );
	m_pEditor->setText( description );
	m_pWidgetStack->raiseWidget( 1 );
}
Example #4
0
bool ContextHelp::saveDescription( const QString & language )
{
	if ( m_lastItemType.isEmpty() )
	{
		KMessageBox::sorry( 0, i18n("Cannot save item description.") );
		return false;
	}
	
	return itemLibrary()->setDescription( m_lastItemType, m_pEditor->text(), language );
}
Example #5
0
void ContextHelp::setBrowserItem( const QString & type )
{
	if ( isEditChanged() )
		return;
	
	QString description = itemLibrary()->description( type, KGlobal::locale()->language() );
	if ( description.isEmpty() )
		return;
	
	QString name;
	LibraryItem * li = itemLibrary()->libraryItem( type );
	if ( li )
		name = li->name();
	else
		name = type;
	
	m_lastItemType = type;
	setContextHelp( name, description );
	m_pEditButton->setEnabled( true );
}
Example #6
0
bool ContextHelp::isEditChanged()
{
	if ( m_lastItemType.isEmpty() )
		return false;
	
	// Is the edit widget raised?
	if ( m_pWidgetStack->visibleWidget() != m_pWidgetStack->widget( 1 ) )
		return false;
	
	// We are currently editing an item. Is it changed?
	return ( m_pEditor->text() != itemLibrary()->description( m_lastItemType, m_currentLanguage ).stripWhiteSpace() );
}
Example #7
0
QStringList ItemDocumentIface::validItemIDs( )
{
	QStringList validIDs;
	
	LibraryItemList * allItems = itemLibrary()->items();
	const LibraryItemList::iterator end = allItems->end();
	for ( LibraryItemList::iterator it = allItems->begin(); it != end; ++it )
	{
		QString id = (*it)->activeID();
		if ( m_pItemDocument->isValidItem(id) )
			validIDs << id.utf8();
	}
	return validIDs;
}
Example #8
0
bool ContextHelp::eventFilter( QObject * watched, QEvent * e )
{
// 	kDebug() << k_funcinfo << "watched="<<watched<<endl;
	
	if ( (watched != m_pEditor) && (watched != m_pEditor->editorViewport()) )
		return false;
	
	switch ( e->type() )
	{
		case QEvent::DragEnter:
		{
			QDragEnterEvent * dragEnter = static_cast<QDragEnterEvent*>(e);
			
			if ( !QString( dragEnter->format() ).startsWith("ktechlab/") )
				break;
			
			dragEnter->acceptAction();
			return true;
		}
			
		case QEvent::Drop:
		{
			QDropEvent * dropEvent = static_cast<QDropEvent*>(e);
			
			if ( !QString( dropEvent->format() ).startsWith("ktechlab/") )
				break;
			
			dropEvent->accept();
			
			QString type;
			QDataStream stream( dropEvent->encodedData( dropEvent->format() ) /*, IO_ReadOnly */ );
			stream >> type;
			
			LibraryItem * li = itemLibrary()->libraryItem( type );
			if ( !li )
				return true;
			
			m_pEditor->insertURL( "ktechlab-help:///" + type, li->name() );
			return true;
		}
			
		default:
			break;
	}
	
	return false;
}
Example #9
0
// static function
ContextHelp::LinkType ContextHelp::extractLinkType( const KUrl & url )
{
	QString path = url.path();
	
	if ( url.protocol() == "ktechlab-help" )
	{
		if ( itemLibrary()->haveDescription( path, KGlobal::locale()->language() ) )
			return HelpLink;
		else
			return NewHelpLink;
	}
	
	if ( url.protocol() == "ktechlab-example" )
		return ExampleLink;
	
	return ExternalLink;
}
Example #10
0
void ContextHelp::slotUpdate( Item * item )
{
	if ( isEditChanged() )
		return;
	
	m_lastItemType = item ? item->type() : QString::null;
	m_pEditButton->setEnabled( item );
	
	if ( !item )
	{
		slotClear();
		return;
	}
	
	m_pWidgetStack->raiseWidget( 0 );
	setContextHelp( item->name(), itemLibrary()->description( m_lastItemType, KGlobal::locale()->language() ) );
}
void OrientationWidget::initFromComponent( Component * component )
{
	const QImage im = itemLibrary()->componentImage( component );
	
	QRect bound = component->boundingRect();
	
	// We want a nice square bounding rect
	const int dy = bound.width() - bound.height();
	if ( dy > 0 )
	{
		bound.setTop( bound.top()-(dy/2) );
		bound.setBottom( bound.bottom()+(dy/2) );
	}
	else if ( dy < 0 )
	{
		bound.setLeft( bound.left()+(dy/2) );
		bound.setRight( bound.right()-(dy/2) );
	}
	

	QPixmap tbPm;
	
	for ( unsigned col = 0; col < 4; ++col )
	{
		for ( unsigned row = 0; row < 2; ++row )
		{
			bool flipped = bool(row);
			int angle = 90 * col;
			
			if ( col || row ) {
				tbPm.convertFromImage( im.transformed(
                        Component::transMatrix( angle, flipped, bound.width()/2, bound.height()/2 ) ) );
            } else {
				tbPm.convertFromImage( im );
            }
			
			//m_toolBtn[row][col]->setPixmap(tbPm);
            m_toolBtn[row][col]->setToDisplayPixmap(tbPm);
            m_toolBtn[row][col]->update();
			m_toolBtn[row][col]->setEnabled(true);
		}
	}
	
	updateShownOrientation();
}
Example #12
0
void ContextHelp::setContextHelp( QString name, QString help )
{
	//BEGIN modify help string as appropriate
	help = help.stripWhiteSpace();
	parseInfo( help );
	RichTextEditor::makeUseStandardFont( & help );
	addLinkTypeAppearances( & help );
	//END modify help string as appropriate
	
	// HACK Adjust top spacing according to whether the item description uses <p>.
	// This is because the help editor uses paragraphs, but old item help stored
	// in the items just uses <br>
	QFont f;
	int fontPixelSize = QFontInfo( f ).pixelSize();
	if ( help.contains( "<p>" ) )
		m_pBrowserView->setMarginHeight( 3-fontPixelSize );
	else
		m_pBrowserView->setMarginHeight( 3 );
	
	m_pNameLabel->setText( name );
	m_pBrowser->begin( itemLibrary()->itemDescriptionsDirectory() );
	m_pBrowser->write( help );
	m_pBrowser->end();
}
Example #13
0
void ItemView::createDragItem(QDragEnterEvent * e) {
	removeDragItem();

	if (!QString(e->format()).startsWith("ktechlab/"))
		return;

	e->accept();

	QString text;

	QDataStream stream(e->encodedData(e->format()), IO_ReadOnly);

	stream >> text;

	QPoint p = mousePosToCanvasPos(e->pos());

	m_pDragItem = itemLibrary()->createItem(text, p_itemDocument, true);

	if (CNItem * cnItem = dynamic_cast<CNItem*>(m_pDragItem))
		cnItem->move(snapToCanvas(p.x()), snapToCanvas(p.y()));
	else m_pDragItem->move(p.x(), p.y());

	m_pDragItem->show();
}
Example #14
0
void ContextHelp::slotInitializeLanguageList()
{
	m_pLanguageSelect->insertStringList( itemLibrary()->descriptionLanguages() );
	m_currentLanguage = KGlobal::locale()->language();
	m_pLanguageSelect->setCurrentItem( m_currentLanguage );
}