This relates to Bug 2095 Note that a handful of translation strings did not merge properlypull/1/head
parent
9782548013
commit
d265f2381c
@ -1,7 +1,7 @@
|
||||
#MIN_CONFIG(3.0.0)
|
||||
KDE_ENABLE_HIDDEN_VISIBILITY
|
||||
|
||||
AM_INIT_AUTOMAKE(kbarcode, 2.0.6)
|
||||
AM_INIT_AUTOMAKE(kbarcode, 2.0.7)
|
||||
AC_C_BIGENDIAN
|
||||
AC_CHECK_KDEMAXPATHLEN
|
||||
|
||||
|
@ -1,427 +0,0 @@
|
||||
/***************************************************************************
|
||||
dsrichtext.cpp - description
|
||||
-------------------
|
||||
begin : Fre Okt 17 2003
|
||||
copyright : (C) 2003 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "dsrichtext.h"
|
||||
|
||||
#ifdef TQT_TEXT_BUG
|
||||
|
||||
// TQt includes
|
||||
#include <tqfontmetrics.h>
|
||||
#include <tqpainter.h>
|
||||
#include <tqregexp.h>
|
||||
|
||||
// for DSREPLACE
|
||||
#include "sqltables.h"
|
||||
|
||||
/*
|
||||
EXAMPLE TEXT:
|
||||
"<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:10pt;font-family:Nimbus Sans l\">"
|
||||
"<p>A little bit <span style=\"font-style:italic;font-weight:600\">formated</span><span style=\"color:#4400ff\"> "
|
||||
"richtext</span> which should be printed to a <span style=\"font-weight:600\">TQPrinter</span> with <span style=\"text-decoration:underline\">TQSimpleRichText</span>. </p>"
|
||||
"<p><span style=\"font-family:Times New Roman;font-size:16pt\">Printing should work in ScreenResolution as well as in HighResolution, but as you can see it will only work in ScreenResolution.</span></p>"
|
||||
"</body></html>";
|
||||
|
||||
Another example
|
||||
<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:10pt;font-family:Nimbus Sans l">
|
||||
<p align="center"><span style="font-size:12pt;font-weight:600;text-decoration:underline">Text test </span><span style="font-size:12pt;font-weight:600;text-decoration:underline;color:#ff0000">label</span></p>
|
||||
<p>Resolution <span style="font-weight:600">formated</span> 108dpi. This text & text should now overlap with the first line. 4 < 6a</p>
|
||||
<p><span style="font-family:Nimbus Sans L;font-weight:600">A</span><span style="font-family:Nimbus Sans L"> longer paragraph with some text, so that I can test wether wordwrap is working. Another "line" to test line spacing without a bigger font (like the one found in the next sentence) messing up the spacing.</span><span style="font-family:Courier [Adobe];font-size:16pt"> Some text "in" a bigger courier font.</span><span style="font-family:Nimbus Sans L"> Also this paragraph should be justified as blockquote.</span><span style="font-family:Nimbus Sans L;color:#ff0004"> I hope it works</span><span style="font-family:Nimbus Sans L"> and KBarcodes text redering will be better than the one found in TQt.</span></p>
|
||||
</body></html>
|
||||
|
||||
*/
|
||||
|
||||
DSRichText::DSRichText( const TQString & t )
|
||||
: text( t )
|
||||
{
|
||||
if( text.find("<html>") == -1 )
|
||||
text = "<html><head><meta name=\"qrichtext\" content=\"1\" /></head><body style=\"font-size:10pt;font-family:Nimbus Sans l\"><p>"
|
||||
+ t + "</p></body></html>";
|
||||
|
||||
//tqDebug( text );
|
||||
|
||||
start = end = pos = 0;
|
||||
x = y = 0;
|
||||
sx = sy = 1.0;
|
||||
m_base = TQFont();
|
||||
|
||||
TQString tmp = parse( text, "<body ", ">", 0 );
|
||||
if( !tmp.isNull() ) {
|
||||
pos += tmp.length();
|
||||
tmp = tmp.left( tmp.length() - 1 );
|
||||
tmp = tmp.mid( 5, tmp.length() - 5 );
|
||||
m_base = parseStyle( parse( tmp, "style=\"", "\"", pos ), &m_color );
|
||||
}
|
||||
|
||||
pos = text.find( "<p", 0 ); // initalize pos correctly
|
||||
while( parseParagraph() ); // empty while loop
|
||||
}
|
||||
|
||||
DSRichText::~DSRichText()
|
||||
{
|
||||
}
|
||||
|
||||
void DSRichText::initFormat( formated_word* f, int alignment )
|
||||
{
|
||||
f->text = TQString();
|
||||
f->line = false;
|
||||
f->alignment = alignment;
|
||||
f->font = m_base;
|
||||
f->color = m_color;
|
||||
}
|
||||
|
||||
void DSRichText::initLine( TQValueList<formated_line>* l )
|
||||
{
|
||||
formated_line li;
|
||||
li.width = 0;
|
||||
li.ascent = 0;
|
||||
li.leading = 0;
|
||||
li.lineSpacing = 0;
|
||||
li.line = false;
|
||||
l->append( li );
|
||||
}
|
||||
|
||||
void DSRichText::updateSpacing( TQValueList<formated_line>* l, TQFontMetrics* fm )
|
||||
{
|
||||
l->last().lineSpacing = (l->last().lineSpacing < fm->lineSpacing()) ? fm->lineSpacing() : l->last().lineSpacing;
|
||||
l->last().ascent = (l->last().ascent < fm->ascent()) ? fm->ascent() : l->last().ascent;
|
||||
l->last().leading = (l->last().leading < fm->leading()) ? fm->leading() : l->last().leading;
|
||||
}
|
||||
|
||||
void DSRichText::fillLines()
|
||||
{
|
||||
for( unsigned int z = 0; z < word_p.count(); z++ ) {
|
||||
WordList words = word_p[z];
|
||||
LineList lines;
|
||||
initLine( &lines );
|
||||
for( unsigned int i = 0; i < words.count(); i++ ) {
|
||||
formated_word word = words[i];
|
||||
lines.last().line = lines.last().line | word.line;
|
||||
|
||||
TQFontMetrics fm( word.font );
|
||||
updateSpacing( &lines, &fm );
|
||||
|
||||
int tw = fm.width( word.text );
|
||||
// word does not fit in the current line, create a new one
|
||||
if( lines.last().width + tw >= w )
|
||||
initLine( &lines );
|
||||
|
||||
// TODO: check here for words longer than one line
|
||||
lines.last().formats.append( word );
|
||||
lines.last().width += tw;
|
||||
}
|
||||
line_p.append( lines );
|
||||
}
|
||||
}
|
||||
|
||||
void DSRichText::draw( TQPainter* p )
|
||||
{
|
||||
/* don't try to draw if there is no space to draw */
|
||||
if( !w || !h )
|
||||
return;
|
||||
|
||||
fillLines();
|
||||
|
||||
painter = p;
|
||||
painter->save();
|
||||
painter->setClipRect( xpos, ypos, int(w*sx), int(h*sy), TQPainter::CoordPainter );
|
||||
|
||||
for( unsigned int z = 0; z < line_p.count(); z++ ) {
|
||||
LineList lines = line_p[z];
|
||||
if( lines.count() && z )
|
||||
y += int( lines[0].lineSpacing * 0.5);
|
||||
|
||||
for( unsigned int i = 0; i < lines.count(); i++ ) {
|
||||
formated_line l = lines[i];
|
||||
|
||||
if( l.formats.count() && l.formats[0].alignment == TQt::AlignJustify && i != lines.count() - 1 ) {
|
||||
// last line in a paragraph is not justified (in blocksatz mode)!
|
||||
drawJustified( &l );
|
||||
} else {
|
||||
for( unsigned int z = 0; z < l.formats.count(); z++ ) {
|
||||
formated_word f = l.formats[z];
|
||||
|
||||
painter->setFont( f.font );
|
||||
painter->setPen( TQPen( f.color ) );
|
||||
|
||||
int a = f.alignment;
|
||||
if( a == TQt::AlignRight ) {
|
||||
a = TQt::AlignLeft;
|
||||
if( !x )
|
||||
x = w - l.width;
|
||||
} else if( a == TQt::AlignHCenter ) {
|
||||
a = TQt::AlignLeft;
|
||||
if( !x )
|
||||
x = ( w - l.width ) / 2;
|
||||
}
|
||||
|
||||
int ya = yDeviation( &l );
|
||||
painter->drawText( xpos + int(x*sx), ypos + int((y+ya)*sy), int(l.width*sx), int(l.lineSpacing * sy), a, f.text );
|
||||
x += painter->fontMetrics().width( f.text );
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y += l.lineSpacing;
|
||||
}
|
||||
}
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void DSRichText::drawJustified( formated_line* line )
|
||||
{
|
||||
int all = 0;
|
||||
for( unsigned int z = 0; z < line->formats.count(); z++ ) {
|
||||
line->formats[z].text = line->formats[z].text.stripWhiteSpace();
|
||||
TQFontMetrics fm( line->formats[z].font );
|
||||
all += fm.width( line->formats[z].text );
|
||||
}
|
||||
|
||||
int x = 0;
|
||||
int space = (w - all) / (line->formats.count() - 1);
|
||||
for( unsigned int z = 0; z < line->formats.count(); z++ ) {
|
||||
painter->setFont( line->formats[z].font );
|
||||
painter->setPen( TQPen( line->formats[z].color ) );
|
||||
|
||||
int ya = yDeviation( line );
|
||||
int tw = painter->fontMetrics().width(line->formats[z].text);
|
||||
painter->drawText( int(x*sx), int((y+ya)*sy), int(tw*sx), int(line->lineSpacing * sy), TQt::AlignAuto, line->formats[z].text );
|
||||
x += tw;
|
||||
x += space;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool DSRichText::parseParagraph()
|
||||
{
|
||||
int alignment = 0;
|
||||
formated_word f;
|
||||
TQString d = parse( text, "<p", "</p>", pos );
|
||||
//tqDebug("D=" + d );
|
||||
//tqDebug("POS=%i", pos );
|
||||
|
||||
pos += d.length();
|
||||
if( d.isNull() )
|
||||
return false;
|
||||
|
||||
d = parseParagraphTag( d, &alignment );
|
||||
|
||||
WordList words;
|
||||
TQString data;
|
||||
initFormat( &f, alignment );
|
||||
|
||||
if( d.isEmpty() ) {
|
||||
// found empty paragraph
|
||||
words.append( f );
|
||||
word_p.append( words );
|
||||
return true;
|
||||
}
|
||||
|
||||
for( unsigned int i = 0; i < d.length(); ) {
|
||||
if( d[i] == '<' || i == (d.length() - 1) ) {
|
||||
if( i == (d.length() - 1) )
|
||||
data.append( d[i] );
|
||||
|
||||
parseWords( data, &f, &words );
|
||||
initFormat( &f, alignment );
|
||||
data = TQString();
|
||||
|
||||
// bail out now, otherwise there is
|
||||
// and endless loop for e.g. <p>a</p>
|
||||
if( i == (d.length() - 1) )
|
||||
break;
|
||||
|
||||
if( d[i] == '<' ) {
|
||||
TQString span = d.mid( i, d.find( ">", i ) - i + 1 );
|
||||
i += span.length();
|
||||
|
||||
if( span.startsWith( "<span " ) ) {
|
||||
initFormat( &f, alignment );
|
||||
f.font = parseStyle( parse( span, "style=\"", "\"", 0 ), &f.color );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data.append( d[i] );
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
word_p.append( words );
|
||||
return true;
|
||||
}
|
||||
|
||||
TQFont DSRichText::parseStyle( const TQString & s, TQColor* color )
|
||||
{
|
||||
TQString style = TQString( s );
|
||||
|
||||
style = style.left( style.length() - 1 );
|
||||
if( style.startsWith("style=\"" ) )
|
||||
style = style.mid( 7, style.length() - 7 );
|
||||
|
||||
TQFont f = m_base;
|
||||
*color = m_color;
|
||||
|
||||
for ( int i = 0; i < style.contains(';')+1; i++ ) {
|
||||
TQString s = style.section( ';', i, i );
|
||||
if( s.isEmpty() )
|
||||
continue;
|
||||
|
||||
if ( s.startsWith("font-size:" ) ) {
|
||||
f.setPointSize( s.mid(10, s.length() - 12).toInt() );
|
||||
} else if ( s.startsWith("font-family:" ) ) {
|
||||
f.setFamily( s.right( s.length() - 12 ) );
|
||||
} else if( s.startsWith( "color:" ) ) {
|
||||
color->setNamedColor( s.right( s.length() - 6 ) );
|
||||
} else if( s.startsWith("text-decoration:") ) {
|
||||
if( s.endsWith( "underline" ) )
|
||||
f.setUnderline( true );
|
||||
/*#if [[[TQT_VERSION IS DEPRECATED]]] >= 0x030200
|
||||
else if( s.endsWith( "overline" ) )
|
||||
f.setOverline( true );
|
||||
#endif */
|
||||
else if( s.endsWith( "line-through" ) )
|
||||
f.setStrikeOut( true );
|
||||
} else if( s.startsWith( "font-style:") ) {
|
||||
if( s.endsWith( "italic" ) || s.endsWith( "oblique" ) )
|
||||
f.setItalic( true );
|
||||
} else if( s.startsWith( "font-weight:" ) ) {
|
||||
bool ok = false;
|
||||
int n = s.right( s.length() - 12 ).toInt( &ok );
|
||||
if( s.endsWith( "bold" ) )
|
||||
f.setBold( true );
|
||||
else if( ok )
|
||||
f.setWeight( n / 8 ); // convert CSS values to TQt values
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
TQString DSRichText::parse( const TQString & t, const TQString & find, const TQString & find2, int start )
|
||||
{
|
||||
int s = t.find( find, start );
|
||||
if( s == -1 || s < start )
|
||||
return TQString();
|
||||
|
||||
int pend = t.find( find2, s + find.length() );
|
||||
if( pend == -1 || pend < (signed int)(s + find.length()) )
|
||||
return TQString();
|
||||
|
||||
TQString text = t.mid( s, pend - s + find2.length() );
|
||||
return text;
|
||||
}
|
||||
|
||||
void DSRichText::setX( int x )
|
||||
{
|
||||
xpos = x;
|
||||
}
|
||||
|
||||
void DSRichText::setY( int y )
|
||||
{
|
||||
ypos = y;
|
||||
}
|
||||
|
||||
void DSRichText::setWidth( int width )
|
||||
{
|
||||
w = width;
|
||||
}
|
||||
|
||||
void DSRichText::setHeight( int height )
|
||||
{
|
||||
h = height;
|
||||
}
|
||||
|
||||
int DSRichText::parseAlignment( const TQString & align )
|
||||
{
|
||||
TQString a = TQString( align );
|
||||
if( a.endsWith("\"") )
|
||||
a = a.left( a.length() - 1 );
|
||||
|
||||
if( a.startsWith("align=\"") )
|
||||
a = a.mid( 7, a.length() - 7 );
|
||||
|
||||
if( a == "left" )
|
||||
return TQt::AlignLeft;
|
||||
else if( a == "center" )
|
||||
return TQt::AlignHCenter;
|
||||
else if( a == "right" )
|
||||
return TQt::AlignRight;
|
||||
else if( a == "justify" )
|
||||
return TQt::AlignJustify;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void DSRichText::parseWords( const TQString & t, formated_word* w, WordList* words )
|
||||
{
|
||||
unsigned int p = 0;
|
||||
for( unsigned int i = 0; i < t.length(); i++ ) {
|
||||
if( (t[i].isSpace() && p != i) || i == t.length() - 1 ) {
|
||||
formated_word word = *w;
|
||||
|
||||
word.text = replaceEscapeSequences( t.mid( p, i + 1 - p ) );
|
||||
|
||||
p = i + 1;
|
||||
words->append( word );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline int DSRichText::yDeviation( const formated_line* line )
|
||||
{
|
||||
// leading = 1 (almost ever)
|
||||
// linespacing = leading + height
|
||||
// height = ascent + descent + 1
|
||||
if( line->lineSpacing != painter->fontMetrics().lineSpacing() ) {
|
||||
return line->ascent + line->leading - painter->fontMetrics().ascent() - painter->fontMetrics().leading();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
TQString DSRichText::replaceEscapeSequences( const TQString & t )
|
||||
{
|
||||
TQString tmp = TQString( t );
|
||||
tmp = tmp.replace( DSREPLACE( "<" ), "<" );
|
||||
tmp = tmp.replace( DSREPLACE( ">" ), ">" );
|
||||
tmp = tmp.replace( DSREPLACE( "&" ), "&" );
|
||||
tmp = tmp.replace( DSREPLACE( """ ), "\"" );
|
||||
return tmp;
|
||||
}
|
||||
|
||||
TQString DSRichText::parseParagraphTag( const TQString &t, int* alignment )
|
||||
{
|
||||
TQString d = TQString( t );
|
||||
if( d.startsWith("<p>") ) {
|
||||
d = d.mid( 3, d.length() - 3 );
|
||||
} else if( d.startsWith("<p ") ) {
|
||||
*alignment = parseAlignment( parse( d, "align=\"", "\"", 0 ) );
|
||||
if( d.contains( ">" ) ) {
|
||||
int x = d.find(">" ) + 1;
|
||||
d = d.mid( x, d.length() - x );
|
||||
}
|
||||
}
|
||||
|
||||
if( d.endsWith("</p>") )
|
||||
d = d.left( d.length() - 4 ); // strlen("</p>");
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
#endif // TQT_TEXT_BUG
|
||||
|
||||
|
@ -1,193 +0,0 @@
|
||||
/***************************************************************************
|
||||
dsrichtext.h - description
|
||||
-------------------
|
||||
begin : Fre Okt 17 2003
|
||||
copyright : (C) 2003 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef DSRICHTEXT_H
|
||||
#define DSRICHTEXT_H
|
||||
|
||||
#define TQT_TEXT_BUG
|
||||
/*#undef TQT_TEXT_BUG*/
|
||||
#ifdef TQT_TEXT_BUG
|
||||
|
||||
#include <tqcolor.h>
|
||||
#include <tqfont.h>
|
||||
#include <tqstring.h>
|
||||
#include <tqvaluelist.h>
|
||||
|
||||
class DSRichText;
|
||||
|
||||
/** This class represents one word,
|
||||
* formated with a font, a color and an
|
||||
* alignment.
|
||||
*/
|
||||
struct formated_word {
|
||||
TQString text;
|
||||
TQFont font;
|
||||
TQColor color;
|
||||
int alignment;
|
||||
bool line;
|
||||
};
|
||||
|
||||
typedef TQValueList<formated_word> WordList;
|
||||
|
||||
/** This structure represents a single line.
|
||||
* Every line contains a list of formated_words.
|
||||
* Wordwrapping has been applied before the line
|
||||
* was created.
|
||||
* lineSpacing, ascent and leading come from the
|
||||
* biggest font in the line.
|
||||
*/
|
||||
struct formated_line {
|
||||
int width;
|
||||
int lineSpacing;
|
||||
int ascent;
|
||||
int leading;
|
||||
bool line;
|
||||
|
||||
WordList formats;
|
||||
};
|
||||
typedef TQValueList<formated_line> LineList;
|
||||
|
||||
class TQColor;
|
||||
class TQPainter;
|
||||
|
||||
/** A richtext rendering class, which draws a piece
|
||||
* of HTML formated richtext on any TQPainter.
|
||||
* This class works with all printer resolutions compared
|
||||
* to the buggy TQSimpleRichText
|
||||
*
|
||||
* rendering the richtext happens in 3 steps:
|
||||
* <ul>
|
||||
* <li> the HTML data is parsed into text_format structures. Each
|
||||
* of these text_format structures may represend multiple lines, but
|
||||
* also single words. This depends on how long a formated text is.
|
||||
* this step happens in the constructor and in parseParagraph()</li>
|
||||
* <li> the text_format structures are parsed into line structures.
|
||||
* In this step the wordwrapping is calculated. Each line structure
|
||||
* has again text_format structures. This is necessary because a line
|
||||
* of text may of course contain different formattings. A line struct is always
|
||||
* a single line of drawn text, not more and not less.
|
||||
* happens in draw() and fillLines()</li>
|
||||
* <li> the line structure is drawn line by line using TQPainter.
|
||||
* happens in draw()</li>
|
||||
* </ul>
|
||||
*
|
||||
* Printing to the screen is easy and the usage does not differ from
|
||||
* TQSimpleRichText. Drawing on TQPrinter is a little bit more complicated.
|
||||
* The most important thing is that you may not use TQPainter::scale().
|
||||
* A small example on how to print on a TQPrinter:
|
||||
* <pre>
|
||||
* TQPrinter printer( TQPrinter::HighResolution );
|
||||
* TQPainter painter( &printer );
|
||||
* TQPaintDeviceMetrics metrics( &printer );
|
||||
* double scalex = (double)metrics.logicalDpiX() / (double)TQPaintDevice::x11AppDpiX();
|
||||
* double scaley = (double)metrics.logicalDpiY() / (double)TQPaintDevice::x11AppDpiY();
|
||||
*
|
||||
* DSRichText dsr( "<html><p>Hallo World</p></html>" );
|
||||
* dsr.setWidth( 200 ); // in screenresolution coordinates
|
||||
* dsr.setHeight( 80 ); // in screenresolution coordinates
|
||||
* painter.translate( 10 * scalex, 10 * scaley ); // draw at 10, 10 instead of 0, 0
|
||||
* dsr.scale( scalex, scaley );
|
||||
* dsr.draw( &painter );
|
||||
* </pre>
|
||||
*
|
||||
*@author Dominik Seichter
|
||||
*/
|
||||
class DSRichText {
|
||||
public:
|
||||
/** construct a DSRichText object. @p t is formated text as produces by TQTextEdit.
|
||||
*/
|
||||
DSRichText( const TQString & t );
|
||||
~DSRichText();
|
||||
|
||||
void setX( int x );
|
||||
void setY( int y );
|
||||
|
||||
/** draw the formated text on the TQPainter* @p p
|
||||
*/
|
||||
void draw( TQPainter* p );
|
||||
/** set the width of the clipping rectangle
|
||||
*/
|
||||
void setWidth( int width );
|
||||
/** set the height of the clipping rectangle
|
||||
*/
|
||||
void setHeight( int height );
|
||||
/** scale everything. This is necessary to print on devices
|
||||
* with another resolution than the screen. TQPainter::scale() won't work.
|
||||
*/
|
||||
void setScale( double x, double y ) {
|
||||
sx = x; sy = y;
|
||||
};
|
||||
|
||||
private:
|
||||
/** parse a single pare of <p></p> elements
|
||||
*/
|
||||
bool parseParagraph();
|
||||
/** remove <p> and </p> from the TQString @p t and return it.
|
||||
* This function is also responsible for getting the
|
||||
* correct alignment of the paragraph.
|
||||
*/
|
||||
TQString parseParagraphTag( const TQString & t, int* alignment );
|
||||
/** parse the align attribute of a <p> tag and return the corresponding TQt alignment value.
|
||||
*/
|
||||
int parseAlignment( const TQString & align );
|
||||
/** parse the css style attribute of a <span> tag and return a matching TQFont for these
|
||||
* style. The font color is saved in the TQColor* @p color.
|
||||
*/
|
||||
TQFont parseStyle( const TQString & s, TQColor* color );
|
||||
TQString parse( const TQString & t, const TQString & find, const TQString & end, int start );
|
||||
void parseWords( const TQString & t, formated_word* w, WordList* words );
|
||||
void initFormat( formated_word* f, int alignment );
|
||||
void initLine( TQValueList<formated_line>* l );
|
||||
void updateSpacing( TQValueList<formated_line>* l, TQFontMetrics* fm );
|
||||
/** draw the line @p line justified as blockquote
|
||||
*/
|
||||
void drawJustified( formated_line* line );
|
||||
/** calculate the y-deviation needed, because of different font sizes in this line
|
||||
*/
|
||||
inline int yDeviation( const formated_line* line );
|
||||
/** replace HTML escape sequences such as < to their real character meaning (i.e. < )
|
||||
*/
|
||||
TQString replaceEscapeSequences( const TQString & t );
|
||||
|
||||
/** fill the line structures with data
|
||||
*/
|
||||
void fillLines();
|
||||
|
||||
int pos; // current position in text
|
||||
int start; // start of a tag
|
||||
int end; // end of a tag
|
||||
int x; // x position
|
||||
int y; // y position
|
||||
int w; // width of the text element
|
||||
int h; // height of the text element
|
||||
int xpos; // x position at the beginning
|
||||
int ypos; // y position at the beginning
|
||||
|
||||
double sx;
|
||||
double sy;
|
||||
|
||||
TQString text;
|
||||
TQFont m_base;
|
||||
TQColor m_color;
|
||||
TQPainter* painter;
|
||||
|
||||
TQValueList<LineList> line_p;
|
||||
TQValueList<WordList> word_p;
|
||||
};
|
||||
|
||||
#endif // TQT_TEXT_BUG
|
||||
#endif
|
@ -1,620 +0,0 @@
|
||||
f/***************************************************************************
|
||||
barcode.cpp - description
|
||||
-------------------
|
||||
begin : Die Apr 23 2002
|
||||
copyright : (C) 2002 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "sqltables.h"
|
||||
#include "barcodecache.h"
|
||||
|
||||
#include "mybarcode.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// TQt includes
|
||||
#include <tqdir.h>
|
||||
#include <tqpainter.h>
|
||||
#include <tqpaintdevicemetrics.h>
|
||||
#include <tqsqlquery.h>
|
||||
|
||||
// KDE includes
|
||||
#include <tdeapplication.h>
|
||||
#include <tdeconfig.h>
|
||||
#include <tdelocale.h>
|
||||
#include <tdemessagebox.h>
|
||||
#include <kprocess.h>
|
||||
#include <kstandarddirs.h>
|
||||
#include <tdetempfile.h>
|
||||
|
||||
#define BARCODE_MARGIN 10 /* Margin added by GNU Barcode to the barcodes */
|
||||
|
||||
TQValueList<barcodeFormat> codes;
|
||||
|
||||
void init() {
|
||||
BarCode::setHaveBarcode();
|
||||
}
|
||||
|
||||
bool barcodeData::operator==( const struct barcodeData d ) const {
|
||||
bool b = ( value == d.value && type == d.type &&
|
||||
scale == d.scale && text == d.text );
|
||||
|
||||
if( BarCode::hasFeature( type, TBARCODEADV ) )
|
||||
b = ( b && tbarcode == d.tbarcode );
|
||||
|
||||
if( BarCode::hasFeature( type, DATAMATRIX ) )
|
||||
b = ( b && datamatrix == d.datamatrix );
|
||||
|
||||
if( BarCode::hasFeature( type, PDF417BARCODE ) )
|
||||
b = ( b && pdf417 == d.pdf417 );
|
||||
|
||||
return b;
|
||||
};
|
||||
|
||||
BarCode::BarCode( const barcodeData* data )
|
||||
{
|
||||
barcode = *data;
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
BarCode::BarCode()
|
||||
{
|
||||
fillDefault( &barcode );
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
BarCode::~BarCode()
|
||||
{
|
||||
}
|
||||
|
||||
const TQPixmap BarCode::pixmap()
|
||||
{
|
||||
if( p.isNull() )
|
||||
createBarcode( &p, TDEApplication::desktop() );
|
||||
|
||||
if( p.isNull() ) {
|
||||
KMessageBox::error( 0, "<qt>" + i18n("Barcode not valid!") + "<br>" + barcode.value + "</qt>" );
|
||||
barcode.valid = false;
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
bool BarCode::createPixmap( TQPixmap* target, int resx, int resy )
|
||||
{
|
||||
KTempFile* output = new KTempFile( TQString(), ".ps" );;
|
||||
output->file()->close();
|
||||
|
||||
KTempFile* input = new KTempFile( TQString(), ".pbm" );
|
||||
input->file()->close();
|
||||
|
||||
m_value = createSequence( barcode.value );
|
||||
|
||||
if( BarCode::hasFeature( barcode.type, PDF417 ) ) {
|
||||
if(!createPdf417( output )) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
} else if( BarCode::hasFeature( barcode.type, TBARCODE ) ) {
|
||||
if(!createTBarcode( output )) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
} else { // if( BarCode::hasFeature( barcode.type, GNU_BARCODE ) ) {
|
||||
TQString flag = barcode.text ? "" : "-n";
|
||||
|
||||
KShellProcess proc;
|
||||
proc << "barcode" << "-E"
|
||||
<< "-b" << KShellProcess::quote( m_value ) << flag
|
||||
<< "-e" << barcode.type << "-o" << output->name();
|
||||
|
||||
proc.start( TDEProcess::Block, TDEProcess::NoCommunication );
|
||||
proc.resume();
|
||||
|
||||
if( proc.exitStatus() ) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
TQFileInfo fi( output->name() );
|
||||
// if file size = 0, error in generation
|
||||
if( !fi.size() ) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
|
||||
TQSize s = getBoundingBox( output->name() );
|
||||
double sw = (double)s.width()/72 * resx;
|
||||
double sh = (double)s.height()/72 * resy;
|
||||
|
||||
KShellProcess proc2;
|
||||
proc2 << "gs" << TQString("-g%1x%2").arg(int(sw*(double)barcode.scale)).arg(int(sh*(double)barcode.scale))
|
||||
<< "-r" + TQString::number( resx*(double)barcode.scale ) + "x" + TQString::number( resy*(double)barcode.scale )
|
||||
<< "-sDEVICE=pbmraw" << "-sOutputFile=" + input->name() << "-sNOPAUSE"
|
||||
<< "-q " + output->name() << "-c showpage" << "-c quit";
|
||||
|
||||
proc2.start( TDEProcess::Block, TDEProcess::NoCommunication );
|
||||
proc2.resume();
|
||||
|
||||
if( proc2.exitStatus() ) {
|
||||
cleanUp( output, input, target );
|
||||
return false;
|
||||
}
|
||||
|
||||
target->load( input->name(), "PBM" );
|
||||
// BarcodeCache::instance()->write( barcode, resx, resy, target, m_value );
|
||||
|
||||
input->unlink();
|
||||
output->unlink();
|
||||
|
||||
delete output;
|
||||
delete input;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void BarCode::createBarcode( TQPixmap* target, TQPaintDevice* device )
|
||||
{
|
||||
TQPaintDeviceMetrics pdm( device );
|
||||
int resx = pdm.logicalDpiX();
|
||||
int resy = pdm.logicalDpiY();
|
||||
|
||||
TQString value = createSequence( barcode.value );
|
||||
TQPixmap* cached = 0;//BarcodeCache::instance()->read( barcode, resx, resy, value );
|
||||
|
||||
// no matching barcode found in cache
|
||||
if( !cached ) {
|
||||
if( !createPixmap( target, resx, resy ) )
|
||||
return;
|
||||
} else {
|
||||
*target = *cached;
|
||||
delete cached;
|
||||
}
|
||||
|
||||
if( BarCode::hasFeature( barcode.type, PDF417 ) ) {
|
||||
// we have to scale to the correct resolution.
|
||||
// we scale already here and not at the end,
|
||||
// so that the addMargin function does not get a scaled margin.
|
||||
TQPaintDeviceMetrics pdm( TDEApplication::desktop() );
|
||||
int screenresx = pdm.logicalDpiX();
|
||||
int screenresy = pdm.logicalDpiY();
|
||||
|
||||
TQWMatrix m;
|
||||
double scalex = (resx/screenresx)*barcode.scale;
|
||||
double scaley = (resy/screenresy)*barcode.scale;
|
||||
m.scale( scalex, scaley );
|
||||
*target = target->xForm( m );
|
||||
}
|
||||
*target = cut( target, barcode.cut );
|
||||
*target = addMargin( target, barcode.margin );
|
||||
|
||||
// Rotate
|
||||
TQWMatrix m;
|
||||
m.rotate( (double)barcode.rotation );
|
||||
*target = target->xForm( m );
|
||||
|
||||
barcode.valid = true;
|
||||
}
|
||||
|
||||
bool BarCode::createPdf417( KTempFile* output )
|
||||
{
|
||||
KTempFile text( TQString(), ".txt" );
|
||||
TQTextStream t( text.file() );
|
||||
t << m_value;
|
||||
text.file()->close();
|
||||
|
||||
// ps does not work use pbm!
|
||||
KShellProcess proc;
|
||||
proc << "pdf417_enc" << "-tps" << text.name() << output->name()
|
||||
<< barcode.pdf417.row
|
||||
<< barcode.pdf417.col
|
||||
<< barcode.pdf417.err;
|
||||
|
||||
proc.start( TDEProcess::Block, TDEProcess::NoCommunication );
|
||||
proc.resume();
|
||||
|
||||
if( proc.exitStatus() ) {
|
||||
text.unlink();
|
||||
return false;
|
||||
}
|
||||
|
||||
text.unlink();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BarCode::createTBarcode( KTempFile* output )
|
||||
{
|
||||
// print text
|
||||
TQString flag = barcode.text ? "" : "n";
|
||||
// escape text
|
||||
flag.append( barcode.tbarcode.escape ? " son" : " soff" );
|
||||
// autocorrection
|
||||
flag.append( barcode.tbarcode.autocorrect ? " Aon" : " Aoff" );
|
||||
// text above
|
||||
flag.append( barcode.tbarcode.above ? " a" : "" );
|
||||
|
||||
KShellProcess proc;
|
||||
proc << "tbarcodeclient" << "-f" + output->name();
|
||||
if( !BarCode::hasFeature( barcode.type, BARCODE2D ) )
|
||||
proc << TQString( "m%1" ).arg( barcode.tbarcode.modulewidth * 1000 );
|
||||
|
||||
if( BarCode::hasFeature( barcode.type, DATAMATRIX ) )
|
||||
proc << TQString( "Ds%1" ).arg( barcode.datamatrix.size );
|
||||
|
||||
if( BarCode::hasFeature( barcode.type, PDF417BARCODE ) )
|
||||
proc << TQString( "Pr%1 Pc%2 Pe%3" ).arg( barcode.pdf417.row )
|
||||
.arg( barcode.pdf417.col )
|
||||
.arg( barcode.pdf417.err );
|
||||
|
||||
proc << barcode.type << "tPS" << TQString("c%1").arg( barcode.tbarcode.checksum ) << flag << "d" + KShellProcess::quote( m_value );
|
||||
proc.start( TDEProcess::Block, TDEProcess::NoCommunication );
|
||||
proc.resume();
|
||||
|
||||
if( proc.exitStatus() )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const TQPixmap BarCode::printerPixmap( TQPaintDevice* device )
|
||||
{
|
||||
if( pp.isNull() )
|
||||
createBarcode( &pp, device );
|
||||
|
||||
return pp;
|
||||
}
|
||||
|
||||
void BarCode::fillDefault( barcodeData* data )
|
||||
{
|
||||
data->margin = 10;
|
||||
data->text = true;
|
||||
data->value = "1234567890";
|
||||
data->type = "code39";
|
||||
data->scale = 1.0;
|
||||
data->cut = 1.0;
|
||||
data->rotation = 0;
|
||||
data->valid = false;
|
||||
|
||||
data->pdf417.row = 24;
|
||||
data->pdf417.col = 8;
|
||||
data->pdf417.err = 5;
|
||||
|
||||
data->datamatrix.size = 0;
|
||||
|
||||
data->tbarcode.modulewidth = 0.353;
|
||||
data->tbarcode.escape = false;
|
||||
data->tbarcode.above = false;
|
||||
data->tbarcode.autocorrect = false;
|
||||
data->tbarcode.checksum = 0;
|
||||
|
||||
data->xml.caption = "Static";
|
||||
data->xml.x = 0;
|
||||
data->xml.y = 0;
|
||||
|
||||
data->sequence.enabled = false;
|
||||
data->sequence.mode = NUM;
|
||||
data->sequence.step = 1;
|
||||
data->sequence.start = 1;
|
||||
}
|
||||
|
||||
void BarCode::redrawBarcode()
|
||||
{
|
||||
p.resize( 0, 0 );
|
||||
pp.resize( 0, 0 );
|
||||
}
|
||||
|
||||
TQPixmap BarCode::cut( TQPixmap* pic, double cut)
|
||||
{
|
||||
if( cut == 1.0 )
|
||||
return (*pic);
|
||||
|
||||
TQPixmap pcut( pic->width(), int((double)pic->height() * cut) );
|
||||
pcut.fill( TQt::white ); // barcode.bg
|
||||
|
||||
TQWMatrix m;
|
||||
/*
|
||||
* if text is above the barcode cut from
|
||||
* below the barcode.
|
||||
*/
|
||||
|
||||
// TODO: put this into one if, I am to stupid today.....
|
||||
if( BarCode::hasFeature( barcode.type, TBARCODEADV ) ) {
|
||||
if( !barcode.tbarcode.above )
|
||||
m.rotate( 180 );
|
||||
} else
|
||||
m.rotate( 180 );
|
||||
|
||||
TQPainter painter( &pcut );
|
||||
painter.drawPixmap( 0, 0, pic->xForm( m ) );
|
||||
|
||||
return pcut.xForm( m );
|
||||
}
|
||||
|
||||
TQPixmap BarCode::addMargin( TQPixmap* pic, int margin )
|
||||
{
|
||||
TQPixmap p;
|
||||
|
||||
/* We have to handle UPC special because of the checksum character
|
||||
* which is printed on the right margin.
|
||||
* The samve goes for ISBN codes.
|
||||
* Any other formats??
|
||||
*/
|
||||
|
||||
bool gnubarcode = BarCode::hasFeature( barcode.type, GNU_BARCODE );
|
||||
double barm = gnubarcode ? BARCODE_MARGIN * barcode.scale : 0;
|
||||
|
||||
// Add margin
|
||||
double sx = barm;
|
||||
double sy = barm;
|
||||
double sw = pic->width() - barm * 2;
|
||||
double sh = pic->height() - barm * 2;
|
||||
|
||||
if( gnubarcode && (barcode.type == "upc" || barcode.type == "isbn") ) {
|
||||
sw = pic->width() - barm;
|
||||
|
||||
p.resize( pic->width() + int(margin*2 - barm), pic->height() + int(margin * 2 - barm * 2) );
|
||||
} else
|
||||
p.resize( pic->width() + int(margin*2 - barm * 2), pic->height() + int(margin * 2 - barm * 2) );
|
||||
|
||||
p.fill( TQt::white ); // barcode.bg
|
||||
TQPainter painter( &p );
|
||||
painter.drawPixmap( margin, margin, *pic, (int)sx, (int)sy, (int)sw, (int)sh );
|
||||
painter.end();
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
const TQString BarCode::getMaxLength( const TQString & name )
|
||||
{
|
||||
TQSqlQuery query("select uid, (length(barcode_no)) as LEN from " TABLE_BASIC
|
||||
" where encoding_type = '" + name +"' ORDER by LEN DESC LIMIT 1" );
|
||||
|
||||
while( query.next() ) {
|
||||
TQSqlQuery queryuid("select barcode_no from barcode_basic where uid = '"
|
||||
+ query.value( 0 ).toString() + "'" );
|
||||
while( queryuid.next() )
|
||||
if(!queryuid.value( 0 ).toString().isEmpty())
|
||||
return queryuid.value( 0 ).toString();
|
||||
}
|
||||
|
||||
TQSqlQuery query1("select uid, (length(barcode_no)) as LEN from " TABLE_CUSTOMER_TEXT
|
||||
" where encoding_type = '" + name +"' ORDER by LEN DESC LIMIT 1" );
|
||||
|
||||
while( query1.next() ) {
|
||||
TQSqlQuery queryuid("select barcode_no from customer_text where uid = '"
|
||||
+ query1.value( 0 ).toString() + "'" );
|
||||
while( queryuid.next() )
|
||||
if(!queryuid.value( 0 ).toString().isEmpty())
|
||||
return queryuid.value( 0 ).toString();
|
||||
}
|
||||
|
||||
return "1234567";
|
||||
}
|
||||
|
||||
void BarCode::cleanUp( KTempFile* file, KTempFile* file2, TQPixmap* target )
|
||||
{
|
||||
target->resize( 0, 0 );
|
||||
|
||||
file->unlink();
|
||||
file2->unlink();
|
||||
delete file;
|
||||
delete file2;
|
||||
}
|
||||
|
||||
TQString BarCode::createSequence( const TQString & value )
|
||||
{
|
||||
if( !barcode.sequence.enabled )
|
||||
return value;
|
||||
|
||||
if( value.contains( '#' ) <= 0 )
|
||||
return value;
|
||||
|
||||
TQString text = value;
|
||||
int pos = 0, counter = 1;
|
||||
|
||||
pos = text.find("#", pos);
|
||||
pos++;
|
||||
while( text[pos] == '#' ) {
|
||||
text.remove(pos, 1);
|
||||
counter++;
|
||||
}
|
||||
|
||||
pos = text.find("#", 0);
|
||||
TQString temp;
|
||||
|
||||
if( barcode.sequence.mode == NUM ) {
|
||||
int v = barcode.sequence.start + m_index*barcode.sequence.step;
|
||||
temp.sprintf("%0*i", counter, v );
|
||||
} else {
|
||||
for( int i = 0; i < counter; i++ )
|
||||
temp.append( "A" );
|
||||
|
||||
unsigned int z = 0;
|
||||
for( int p = temp.length(); p >= 0; p--, z++ ) {
|
||||
if( barcode.sequence.mode == ALPHA ) {
|
||||
int v = 'A' + m_index*barcode.sequence.step;
|
||||
v -= z*('Z'-'A');
|
||||
|
||||
if( v <= 'Z' ) {
|
||||
temp[p] = TQChar(v);
|
||||
break;
|
||||
} else if( v > 'Z' )
|
||||
v = 'Z';
|
||||
temp[p] = TQChar(v);
|
||||
} else if( barcode.sequence.mode == ALPHANUM ) {
|
||||
tqDebug("NOT IMPLEMENTED");
|
||||
/* char array[36];
|
||||
for( unsigned int i = 'A'; i <= 'Z'; i++ )
|
||||
array[i-'A'] = i;
|
||||
for( unsigned int i = '0'; i <= '9'; i++ )
|
||||
array['Z'-'A'+i-'0'] = i;
|
||||
|
||||
int z = m_index*barcode.sequence.step;
|
||||
if( z < sizeof(array) )
|
||||
temp[]
|
||||
int v = array[ ]*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text.replace( pos, 1, temp);
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
TQString BarCode::sequenceValue()
|
||||
{
|
||||
return createSequence( barcode.value );
|
||||
}
|
||||
|
||||
bool BarCode::hasFeature( const TQString & type, unsigned int feature )
|
||||
{
|
||||
for( unsigned int i = 0; i < codes.count(); i++ )
|
||||
if( codes[i].name == type )
|
||||
return (codes[i].features & feature) == feature;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TQSize BarCode::getBoundingBox( const TQString & filename )
|
||||
{
|
||||
TQSize s(0,0);
|
||||
TQFile f( filename );
|
||||
if( !f.open( IO_ReadOnly ) )
|
||||
return s;
|
||||
|
||||
TQString t;
|
||||
while( f.readLine( t, 1000 ) != -1 )
|
||||
{
|
||||
if( t.startsWith( "%%BoundingBox:") )
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
t = t.right( t.length() - 14 );
|
||||
sscanf( (const char*)t, "%d %d %d %d", &x, &y, &w, &h );
|
||||
s = TQSize( w, h );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
f.close();
|
||||
return s;
|
||||
}
|
||||
|
||||
bool BarCode::m_haveGnuBarcode = false;
|
||||
bool BarCode::m_havePdfEncode = false;
|
||||
bool BarCode::m_haveTBarcode = false;
|
||||
|
||||
barcodeFormat BarCode::fillStruct( const TQString & name, const TQString & text, const int feature )
|
||||
{
|
||||
barcodeFormat t;
|
||||
t.name = name;
|
||||
t.text = text;
|
||||
t.features = feature;
|
||||
return t;
|
||||
}
|
||||
|
||||
void BarCode::setHaveBarcode()
|
||||
{
|
||||
m_haveGnuBarcode = !TDEStandardDirs::findExe( "barcode" ).isNull();
|
||||
m_havePdfEncode = !TDEStandardDirs::findExe( "pdf417_enc" ).isNull();
|
||||
m_haveTBarcode = !TDEStandardDirs::findExe( "tbarcodeclient" ).isNull();
|
||||
|
||||
if( codes.count() == 0 ) {
|
||||
if( m_haveGnuBarcode ) {
|
||||
codes.append( fillStruct( "ean", i18n("EAN (EAN 8 or EAN 13)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "upc", i18n("UPC (12-digit EAN; UPCA and UPCB)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "isbn", i18n("ISBN (still EAN13)"), GNU_BARCODE | NOCUT ) );
|
||||
codes.append( fillStruct( "code39", i18n("Code 39"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "code39 -c", i18n("Code 39 (no checksum)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "code128", i18n("Code 128 (a,b,c: autoselection)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "code128c", i18n("Code 128C (compact form digits)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "code128b", i18n("Code 128B, full printable ascii"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "i25", i18n("interleaved 2 of 5 (only digits)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "i25 -c", i18n("interleaved 2 of 5 (only digits, no checksum)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "128raw", i18n("Raw code 128"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "cbr", i18n("Codabar"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "cbr -c", i18n("Codabar (no checksum)"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "msi", i18n("MSI"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "pls", i18n("Plessey"), GNU_BARCODE ) );
|
||||
codes.append( fillStruct( "code93", i18n("Code 93"), GNU_BARCODE ) );
|
||||
}
|
||||
|
||||
if( m_havePdfEncode ) {
|
||||
codes.append( fillStruct( "pdf417", i18n("pdf 417 2D Barcode"), BARCODE2D | PDF417 | PDF417BARCODE ) );
|
||||
}
|
||||
|
||||
if( m_haveTBarcode ) {
|
||||
codes.append( fillStruct( "b1", "Code 11", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b2", "Code 2 of 5 (Standard)", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b3", "Interleaved 2 of 5 Standard", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b4", "Code 2 of 5 IATA", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b5", "Code 2 of 5 Matrix", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b6", "Code 2 of 5 Data Logic", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b7", "Code 2 of 5 Industrial", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b8", "Code 3 of 9 (Code 39)", TBARCODE | TBARCODEADV | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b9", "Code 3 of 9 (Code 39) ASCII", TBARCODE | TBARCODEADV | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b10", "EAN8", TBARCODE | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b11", "EAN8 - 2 digits add on", TBARCODE | NOCUT | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b12", "EAN8 - 5 digits add on", TBARCODE | NOCUT | TBARCODEADV | EAN8CHECK | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b13", "EAN13", TBARCODE | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b14", "EAN13 - 2 digits add on", TBARCODE | NOCUT | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b15", "EAN13 - 5 digits add on", TBARCODE | NOCUT | TBARCODEADV | EAN13CHECK | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b16", "EAN128 (supports AIS)", TBARCODE | TBARCODEADV | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b17", "UPC 12 Digits", TBARCODE | TBARCODEADV | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b18", "CodaBar (2 width)", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b19", "CodaBar (18 widths)", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b20", "Code128", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b21", "Deutsche Post Leitcode", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b22", "Deutsche Post Identcode", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b25", "Code 93", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b26", "Identical to eBC_UPCA", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b33", "UCC128 (= EAN128)", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b34", "UPC A", TBARCODE | TBARCODEADV | TBARCODEADV | UPCACHECK ) );
|
||||
codes.append( fillStruct( "b35", "UPC A - 2 digit add on", TBARCODE | TBARCODEADV | UPCACHECK ) );
|
||||
codes.append( fillStruct( "b36", "UPC A - 5 digit add on", TBARCODE | TBARCODEADV | UPCACHECK ) );
|
||||
codes.append( fillStruct( "b37", "UPC E", TBARCODE | TBARCODEADV | UPCECHECK ) );
|
||||
codes.append( fillStruct( "b38", "UPC E - 2 digit add on", TBARCODE | TBARCODEADV | UPCECHECK ) );
|
||||
codes.append( fillStruct( "b39", "UPC E - 5 digit add on", TBARCODE | TBARCODEADV | UPCECHECK ) );
|
||||
codes.append( fillStruct( "b40", "PostNet ZIP (5d.)", TBARCODE | NOCUT | TBARCODEADV | POSTNETCHECK ) );
|
||||
codes.append( fillStruct( "b41", "PostNet ZIP (5d.+CD)", TBARCODE | NOCUT | TBARCODEADV | POSTNETCHECK ) );
|
||||
codes.append( fillStruct( "b42", "PostNet ZIP (8d.)", TBARCODE | NOCUT | TBARCODEADV | POSTNETCHECK ) );
|
||||
codes.append( fillStruct( "b43", "PostNet ZIP+4 (5d.+4d.+CD)", TBARCODE | NOCUT | TBARCODEADV | POSTNETCHECK ) );
|
||||
codes.append( fillStruct( "b44", "PostNet DPBC (5d.+4d.+2d.)", TBARCODE | NOCUT | TBARCODEADV | POSTNETCHECK ) );
|
||||
codes.append( fillStruct( "b45", "PostNet DPBC (5d.+4d.+2d.+CD)", TBARCODE | NOCUT | TBARCODEADV | POSTNETCHECK ) );
|
||||
codes.append( fillStruct( "b46", "Plessey Code", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b47", "MSI Code", TBARCODE | TBARCODEADV | MODULO10CHECK ) );
|
||||
codes.append( fillStruct( "b50", "LOGMARS", TBARCODE | TBARCODEADV | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b55", "PDF417 - 2D bar code", TBARCODE | BARCODE2D | PDF417BARCODE ) );
|
||||
codes.append( fillStruct( "b56", "PDF417 Truncated - 2D bar code", TBARCODE | BARCODE2D | PDF417BARCODE ) );
|
||||
codes.append( fillStruct( "b57", "MaxiCode - 2D-bar code (Postscript only)", TBARCODE | BARCODE2D ) );
|
||||
codes.append( fillStruct( "b58", "QR-Code", TBARCODE | BARCODE2D ) );
|
||||
codes.append( fillStruct( "b59", "Code128 (CharSet A)", TBARCODE | TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b60", "Code128 (CharSet B)", TBARCODE | TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b61", "Code128 (CharSet C)", TBARCODE | TBARCODEADV | CODE128CHECK | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b62", "Code 93 Ascii", TBARCODE | TBARCODEADV | MODULOALLCHECK ) );
|
||||
codes.append( fillStruct( "b63", "Australian Post Standard Customer", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b64", "Australian Post Customer 2", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b65", "Australian Post Customer 3", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b66", "Australian Post Reply Paid", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b67", "Australian Post Routing", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b68", "Australian Post Redirection", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b69", "ISBN Code (=EAN13P5)", TBARCODE | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b70", "Royal Mail 4 State (RM4SCC)", TBARCODE | NOCUT | TBARCODEADV ) );
|
||||
codes.append( fillStruct( "b71", "Data Matrix", DATAMATRIX | TBARCODE | BARCODE2D | NOSCALE ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,304 +0,0 @@
|
||||
/***************************************************************************
|
||||
mybarcode.h - description
|
||||
-------------------
|
||||
begin : Die Apr 23 2002
|
||||
copyright : (C) 2002 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef MY_BARCODE_H
|
||||
#define MY_BARCODE_H
|
||||
|
||||
#include <tqpixmap.h>
|
||||
#include <tqobject.h>
|
||||
|
||||
#include <tqvaluelist.h>
|
||||
#include "barkode.h"
|
||||
void init();
|
||||
|
||||
typedef union u_settings {
|
||||
struct {
|
||||
int row;
|
||||
int col;
|
||||
int err;
|
||||
} pdf417;
|
||||
|
||||
struct {
|
||||
int size;
|
||||
} datamatrix;
|
||||
|
||||
struct {
|
||||
double modulewidth;
|
||||
bool escape;
|
||||
} tbarcode;
|
||||
};
|
||||
|
||||
class TQColor;
|
||||
class TQString;
|
||||
typedef struct barcodeData {
|
||||
TQString value;
|
||||
TQString type;
|
||||
int margin;
|
||||
int rotation;
|
||||
double scale;
|
||||
double cut;
|
||||
bool text;
|
||||
bool valid;
|
||||
|
||||
struct _pdf417 {
|
||||
int row;
|
||||
int col;
|
||||
int err;
|
||||
|
||||
bool operator==( const struct _pdf417 p ) const {
|
||||
return row == p.row && col == p.col && err == p.err;
|
||||
};
|
||||
|
||||
} pdf417;
|
||||
|
||||
struct _datamatrix {
|
||||
int size;
|
||||
|
||||
bool operator==( const struct _datamatrix d ) const {
|
||||
return size == d.size;
|
||||
};
|
||||
|
||||
} datamatrix;
|
||||
|
||||
struct _tbarcode {
|
||||
double modulewidth;
|
||||
bool escape;
|
||||
bool above;
|
||||
bool autocorrect;
|
||||
int checksum;
|
||||
|
||||
bool operator==( const struct _tbarcode t ) const {
|
||||
return modulewidth == t.modulewidth && escape == t.escape && above == t.above && checksum == t.checksum && autocorrect == t.autocorrect;
|
||||
};
|
||||
|
||||
} tbarcode;
|
||||
|
||||
struct {
|
||||
// only important
|
||||
// when this struct
|
||||
// is read from XML
|
||||
TQString caption;
|
||||
int x;
|
||||
int y;
|
||||
} xml;
|
||||
|
||||
/**
|
||||
* Compare to barcodeData structs,
|
||||
* but only the fields which are used
|
||||
* as commandline parameters for
|
||||
* the genaration backends.
|
||||
* E.g. margin is not compared, because
|
||||
* the margin is created by KBarcode internally.
|
||||
*/
|
||||
bool operator==( const struct barcodeData d ) const;
|
||||
|
||||
struct {
|
||||
bool enabled;
|
||||
int mode;
|
||||
int step;
|
||||
int start;
|
||||
} sequence;
|
||||
};
|
||||
|
||||
#if 0
|
||||
enum { NOCUT = 0x00001, MULTILINE = 0x00002, NOTEXT = 0x00004, NOSCALE = 0x00008,
|
||||
/**
|
||||
* The different Generator Backends
|
||||
*/
|
||||
GNU_BARCODE = 0x00010, PDF417 = 0x00020, TBARCODE = 0x00040,
|
||||
/**
|
||||
* Different advanced option modes.
|
||||
*/
|
||||
DATAMATRIX = 0x00080, PDF417BARCODE = 0x00100, TBARCODEADV = 0x00200,
|
||||
/**
|
||||
* Checksum ID's
|
||||
*/
|
||||
POSTNETCHECK = 0x01000, CODE128CHECK = 0x02000, EAN8CHECK = 0x04000, EAN13CHECK = 0x08000,
|
||||
UPCACHECK = 0x10000, UPCECHECK = 0x20000, MODULOALLCHECK = 0x40000, MODULO10CHECK = 0x80000,
|
||||
/**
|
||||
* Short cut's
|
||||
*/
|
||||
BARCODE2D = NOCUT | MULTILINE | NOTEXT };
|
||||
#endif
|
||||
|
||||
typedef struct barcodeFormat {
|
||||
TQString name;
|
||||
TQString text;
|
||||
unsigned int features;
|
||||
};
|
||||
|
||||
class TDEProcess;
|
||||
class KTempFile;
|
||||
class TQPaintDevice;
|
||||
/**
|
||||
* This class creates a TQPixmap from a barcodeData struct.
|
||||
* Several backends are supported to generate the pixmap.
|
||||
* GNU Barcode
|
||||
* pdf417_enc
|
||||
* TBarcode (http://www.tec-it.com)
|
||||
*
|
||||
* This tools generate a postscript file. The ps file is
|
||||
* transformed to a PBM file scaled to the requested resolution
|
||||
* or screen resolution using ghostscript.
|
||||
*
|
||||
* The generated barcodes are cached using BarcodeCache.
|
||||
* To fill a barcodeData struct with data from the user, you
|
||||
* might want to use BarcodeWidget.
|
||||
*
|
||||
* A small example, of how to generate a valid Barcode in your application
|
||||
* without the use of BarcodeWidget:
|
||||
* <pre>
|
||||
* barcodeData data;
|
||||
* BarCode::fillDefault( &data ); // setup a barcode object with valid data
|
||||
* data.value = "KBARCODE";
|
||||
* data.type = "code39";
|
||||
* BarCode b( &data ); // create a barcode object
|
||||
* TQPixmap p = b.pixmap(); // get a pixmap of the barcode
|
||||
* </pre>
|
||||
*
|
||||
* @see BarcodeCache @see BarcodeWidget
|
||||
* @author Dominik Seichter
|
||||
*/
|
||||
class BarCode {
|
||||
public:
|
||||
/** Create a BarCode object from the data const barcodeData* @p data.
|
||||
* You may delete @p data afterwards. Be sure to call at least once
|
||||
* BarCode::fillDefault() on @p data. Otherwise you rsik invalid barcode data.
|
||||
*/
|
||||
BarCode( const barcodeData* data );
|
||||
/** Create a BarCode object filled with default data.
|
||||
*/
|
||||
BarCode();
|
||||
~BarCode();
|
||||
|
||||
/** Get a TQPixmap of the current barcodeData in
|
||||
* screen resolution-
|
||||
*/
|
||||
const TQPixmap pixmap();
|
||||
/** Get a TQPixmap of the barcode in the same resolution as the
|
||||
* TQPaintDevice* @p device. This is necessary if you want to print
|
||||
* your barcodes, as they won't be scanable in screen resolution.
|
||||
*/
|
||||
const TQPixmap printerPixmap( TQPaintDevice* device );
|
||||
|
||||
/** Set the index of the barcodes for barcode sequences.
|
||||
*/
|
||||
void setIndex( int i ) { m_index = i; }
|
||||
/** Change the barcodeData to @p d, call redraw() afterwards.
|
||||
*/
|
||||
void setData( barcodeData* d ) { barcode = *d; }
|
||||
bool validBarcode() {return !p.isNull();}
|
||||
|
||||
barcodeData data() const { return barcode; }
|
||||
|
||||
TQString sequenceValue();
|
||||
|
||||
/** Fill @p barcodeData* data with its default parameters.
|
||||
* Always call this function, after you have created a new
|
||||
* barcodeData struct.
|
||||
*/
|
||||
static void fillDefault( barcodeData* data );
|
||||
|
||||
/** Test if the encodingType @p type has a certain
|
||||
* @p feature, as defined in the codes TQValueList.
|
||||
*/
|
||||
static bool hasFeature( const TQString & type, unsigned int feature );
|
||||
|
||||
/** get the meximum length of value for the encoding type @p name
|
||||
* from the SQL databases.
|
||||
*/
|
||||
static const TQString getMaxLength( const TQString & name );
|
||||
|
||||
/** This function has to be called befor barcode support is avaible.
|
||||
* It searches for the barcode generation backends
|
||||
* (gnu barcode, tbarcode and pdf417) and fills the TQValueList codes
|
||||
* with data and information about the avaible barcode encoding types.
|
||||
* You only have to call this function once.
|
||||
* The results can be retrieved with the following functions:
|
||||
* @see haveBarcode()
|
||||
* @see haveTBarcode()
|
||||
* @see havePDFBarcode()
|
||||
*/
|
||||
static void setHaveBarcode();
|
||||
static bool haveBarcode() {
|
||||
return ( m_haveGnuBarcode || m_havePdfEncode || m_haveTBarcode );
|
||||
}
|
||||
static bool haveGNUBarcode() {
|
||||
return m_haveGnuBarcode;
|
||||
}
|
||||
static bool haveTBarcode() {
|
||||
return m_haveTBarcode;
|
||||
}
|
||||
static bool havePDFBarcode() {
|
||||
return m_havePdfEncode;
|
||||
}
|
||||
|
||||
/** call this, always after you changed the barcodeData using setData,
|
||||
* so that the pixmaps are recreated.
|
||||
*/
|
||||
void redrawBarcode();
|
||||
private:
|
||||
bool createPixmap( TQPixmap* target, int resx, int resy );
|
||||
void createBarcode( TQPixmap* target, TQPaintDevice* device );
|
||||
bool createPdf417( KTempFile* output );
|
||||
bool createTBarcode( KTempFile* output );
|
||||
TQString createSequence( const TQString & value );
|
||||
/** reads the bounding box information from a postscript file
|
||||
*/
|
||||
TQSize getBoundingBox( const TQString & filename );
|
||||
|
||||
void cleanUp( KTempFile* file, KTempFile* file2, TQPixmap* target );
|
||||
static barcodeFormat fillStruct( const TQString & name, const TQString & text, const int feature );
|
||||
|
||||
/**
|
||||
* Cut the barcode either on the top or
|
||||
* on the bottom, depending on the text position.
|
||||
*
|
||||
* @param pic the TQPixmap that will be cutted
|
||||
* @param cut a value between 0.0 and 1.0. If cut = 1.0
|
||||
* then no cut will happen, if cut = 0.5, half of
|
||||
* the barcode is going to be cutted away.
|
||||
*/
|
||||
TQPixmap cut( TQPixmap* pic, double cut );
|
||||
|
||||
/**
|
||||
* Add a margin to the TQPixmap pic.
|
||||
* @param pic the TQPixmap pic which should get a margin
|
||||
* @param margin the margin size in pixels.
|
||||
*/
|
||||
TQPixmap addMargin( TQPixmap* pic, int margin );
|
||||
|
||||
|
||||
/**
|
||||
* The barcode is generated from this value.
|
||||
* This is necessary so that sequences will work.
|
||||
*/
|
||||
TQString m_value;
|
||||
|
||||
/** index for barcode sequences;
|
||||
*/
|
||||
int m_index;
|
||||
|
||||
TQPixmap p;
|
||||
TQPixmap pp;
|
||||
barcodeData barcode;
|
||||
static bool m_haveGnuBarcode;
|
||||
static bool m_havePdfEncode;
|
||||
static bool m_haveTBarcode;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,23 +0,0 @@
|
||||
|
||||
/***************************************************************************
|
||||
referencecounted.cpp - description
|
||||
-------------------
|
||||
begin : Mo Apr 18 2005
|
||||
copyright : (C) 2005 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
***************************************************************************/
|
||||
|
||||
#include "referencecounted.h"
|
||||
|
||||
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,188 +0,0 @@
|
||||
/***************************************************************************
|
||||
tdeactionmap.cpp - description
|
||||
-------------------
|
||||
begin : Fri Mai 19 2006
|
||||
copyright : (C) 2006 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "tdeactionmap.h"
|
||||
|
||||
#include <tqimage.h>
|
||||
#include <tqlabel.h>
|
||||
#include <tqlayout.h>
|
||||
#include <tqmenubar.h>
|
||||
#include <tqmenudata.h>
|
||||
#include <tqpixmap.h>
|
||||
#include <tqpopupmenu.h>
|
||||
#include <tqregexp.h>
|
||||
#include <tqvbox.h>
|
||||
|
||||
#include <tdeaction.h>
|
||||
#include <tdeapplication.h>
|
||||
#include <tdelistview.h>
|
||||
#if TDE_VERSION >= 0x030500
|
||||
#include <tdelistviewsearchline.h>
|
||||
#endif
|
||||
#include <tdelocale.h>
|
||||
|
||||
class TDEListViewActionItem : public TDEListViewItem {
|
||||
public:
|
||||
TDEListViewActionItem( TDEListView* parent, TDEAction* action )
|
||||
: TDEListViewItem( parent ), m_action( action )
|
||||
{
|
||||
TQPixmap pix;
|
||||
TQSize size = TQIconSet::iconSize( TQIconSet::Large );
|
||||
TQIconSet iconset = m_action->iconSet( TDEIcon::Panel, TDEIcon::SizeLarge );
|
||||
TQRegExp regtag( "<[^>]*>" );
|
||||
|
||||
pix = iconset.pixmap( TQIconSet::Large, TQIconSet::Normal ); // m_action->isEnabled() ? TQIconSet::Normal : TQIconSet::Disabled );
|
||||
if( pix.isNull() )
|
||||
{
|
||||
pix.resize( size );
|
||||
pix.fill( backgroundColor() );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( pix.size() != size )
|
||||
{
|
||||
pix = pix.convertToImage().smoothScale( size );
|
||||
}
|
||||
}
|
||||
|
||||
setText( 0, m_action->plainText() );
|
||||
setText( 1, m_action->shortcutText() );
|
||||
// replace HTML tags in What's this help
|
||||
setText( 2, m_action->whatsThis().replace( regtag, "" ) );
|
||||
setPixmap( 0, pix );
|
||||
}
|
||||
|
||||
void paintCell( TQPainter *p, const TQColorGroup &cg,
|
||||
int column, int width, int alignment )
|
||||
{
|
||||
TQColorGroup _cg( cg );
|
||||
TQColor c = _cg.text();
|
||||
if( m_action && !m_action->isEnabled() )
|
||||
_cg.setColor( TQColorGroup::Text, TQt::gray );
|
||||
|
||||
TDEListViewItem::paintCell( p, _cg, column, width, alignment );
|
||||
_cg.setColor( TQColorGroup::Text, c );
|
||||
}
|
||||
|
||||
inline TDEAction* action() const
|
||||
{
|
||||
return m_action;
|
||||
}
|
||||
|
||||
private:
|
||||
TDEAction* m_action;
|
||||
};
|
||||
|
||||
TDEActionMapDlg::TDEActionMapDlg( TDEActionCollection* actions, TQWidget* parent, const char* name )
|
||||
: KDialogBase( parent, name, false, i18n("Action Map"), KDialogBase::Close, KDialogBase::Close )
|
||||
{
|
||||
TQVBox *page = makeVBoxMainWidget();
|
||||
|
||||
new TQLabel( i18n("Find and execute actions."), page );
|
||||
m_map = new TDEActionMap( actions, page );
|
||||
|
||||
show();
|
||||
}
|
||||
|
||||
void TDEActionMapDlg::updateEnabledState()
|
||||
{
|
||||
m_map->updateEnabledState();
|
||||
}
|
||||
|
||||
TDEActionMap::TDEActionMap( TDEActionCollection* actions, TQWidget* parent, const char* name )
|
||||
: TQWidget( parent, name ), m_actions( actions ), m_showMenuTree( true ), m_grayOutItems( false )
|
||||
{
|
||||
TQVBoxLayout* layout = new TQVBoxLayout( this );
|
||||
|
||||
m_listView = new TDEListView( this );
|
||||
#if TDE_VERSION >= 0x030500
|
||||
m_searchLine = new TDEListViewSearchLineWidget( m_listView, this );
|
||||
#endif
|
||||
|
||||
m_listView->addColumn( i18n("Action") );
|
||||
m_listView->addColumn( i18n("Shortcut") );
|
||||
m_listView->addColumn( i18n("Description") );
|
||||
m_listView->setColumnWidthMode( 0, TQListView::Maximum );
|
||||
m_listView->setColumnWidthMode( 1, TQListView::Maximum );
|
||||
m_listView->setColumnWidthMode( 2, TQListView::Manual );
|
||||
m_listView->setSorting( 0 );
|
||||
m_listView->setAllColumnsShowFocus( true );
|
||||
|
||||
#if TDE_VERSION >= 0x030500
|
||||
layout->addWidget( m_searchLine );
|
||||
#endif
|
||||
layout->addWidget( m_listView );
|
||||
|
||||
connect( m_listView, TQT_SIGNAL( executed( TQListViewItem* ) ), this, TQT_SLOT( slotExecuteAction( TQListViewItem* ) ) );
|
||||
connect( actions, TQT_SIGNAL( inserted( TDEAction* ) ), this, TQT_SLOT( slotActionCollectionChanged() ) );
|
||||
connect( actions, TQT_SIGNAL( removed( TDEAction* ) ), this, TQT_SLOT( slotActionCollectionChanged() ) );
|
||||
slotActionCollectionChanged();
|
||||
}
|
||||
|
||||
TDEActionMap::~TDEActionMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TDEActionMap::slotActionCollectionChanged()
|
||||
{
|
||||
TDEActionPtrList actions;
|
||||
TDEActionPtrList::const_iterator it;
|
||||
|
||||
m_listView->clear();
|
||||
|
||||
if( !m_actions )
|
||||
return;
|
||||
|
||||
actions = m_actions->actions();
|
||||
it = actions.begin();
|
||||
|
||||
while( it != actions.end() )
|
||||
{
|
||||
/*
|
||||
if( m_showMenuTree )
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
new TDEListViewActionItem( m_listView, (*it) );
|
||||
|
||||
connect( *it, TQT_SIGNAL( enabled(bool) ), this, TQT_SLOT( updateEnabledState() ) );
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TDEActionMap::slotExecuteAction( TQListViewItem* item )
|
||||
{
|
||||
TDEListViewActionItem* action = dynamic_cast<TDEListViewActionItem*>(item);
|
||||
if( !action )
|
||||
return;
|
||||
|
||||
if( !action->action()->isEnabled() )
|
||||
return;
|
||||
|
||||
action->action()->activate();
|
||||
}
|
||||
|
||||
void TDEActionMap::updateEnabledState()
|
||||
{
|
||||
m_listView->repaintContents();
|
||||
}
|
||||
|
||||
#include "tdeactionmap.moc"
|
@ -1,102 +0,0 @@
|
||||
/***************************************************************************
|
||||
tdeactionmap.h - description
|
||||
-------------------
|
||||
begin : Fri Mai 19 2006
|
||||
copyright : (C) 2006 by Dominik Seichter
|
||||
email : domseichter@web.de
|
||||
***************************************************************************/
|
||||
|
||||
/***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation; either version 2 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _TDEACTION_MAP_H_
|
||||
#define _TDEACTION_MAP_H_
|
||||
|
||||
#include <tqwidget.h>
|
||||
#include <tdeversion.h>
|
||||
#include <kdialogbase.h>
|
||||
|
||||
class TDEActionCollection;
|
||||
class TDEActionMap;
|
||||
#if TDE_VERSION >= 0x030500
|
||||
class TDEListViewSearchLineWidget;
|
||||
#endif
|
||||
class TDEListView;
|
||||
class TQListViewItem;
|
||||
|
||||
/** Open a simple dialog containing an action map.
|
||||
*/
|
||||
class TDEActionMapDlg : public KDialogBase {
|
||||
public:
|
||||
TDEActionMapDlg( TDEActionCollection* actions, TQWidget* parent = NULL, const char* name = NULL );
|
||||
|
||||
/** Call this function whenever you changed the enabled/disalbed state of an action
|
||||
* in your application.
|
||||
*/
|
||||
void updateEnabledState();
|
||||
|
||||
private:
|
||||
TDEActionMap* m_map;
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is an implementation of an Action Map for KDE.
|
||||
*
|
||||
*
|
||||
* What is an Action Map?
|
||||
*
|
||||
* Almost every web page has a site map. According to Wikipedia,
|
||||
* a site map "helps visitors, and search engine robots, to find
|
||||
* pages on the site". Similar an Action Map should help the
|
||||
* user to find actions (i.e. functions or menu items) in an application.
|
||||
*
|
||||
* More concrete an Action Map is a dialog with a list of all
|
||||
* actions (i.e. make text bold, save file or insert image)
|
||||
* that can be performed in the application at its current state.
|
||||
* Additionally there is a search box at the top of the list so
|
||||
* that the user can search the list easily for a special action.
|
||||
* The action is executed by clicking on it. Disabled actions are
|
||||
* grayed out and cannot be clicked. The dialog is modeless so that
|
||||
* it can always be open and the normal usage of the application is not disturbed.
|
||||
*/
|
||||
class TDEActionMap : public TQWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** Creates a new TDEActionMap widget
|
||||
* @param action all actions from this TDEActionCollection are displayed.
|
||||
* @param parent the parent
|
||||
* @param name the name
|
||||
*/
|
||||
TDEActionMap( TDEActionCollection* actions, TQWidget* parent = NULL, const char* name = NULL );
|
||||
~TDEActionMap();
|
||||
|
||||
public slots:
|
||||
/** Call this function whenever you changed the enabled/disalbed state of an action
|
||||
* in your application.
|
||||
*/
|
||||
void updateEnabledState();
|
||||
|
||||
private slots:
|
||||
void slotActionCollectionChanged();
|
||||
void slotExecuteAction( TQListViewItem* item );
|
||||
|
||||
private:
|
||||
TDEActionCollection* m_actions;
|
||||
TDEListView* m_listView;
|
||||
#if TDE_VERSION >= 0x030500
|
||||
TDEListViewSearchLineWidget* m_searchLine;
|
||||
#endif
|
||||
|
||||
bool m_showMenuTree;
|
||||
bool m_grayOutItems;
|
||||
};
|
||||
|
||||
#endif // _TDEACTION_MAP_H_
|
Loading…
Reference in new issue