Back to index

im-sdk  12.3.91
IIIMText.cpp
Go to the documentation of this file.
00001 #include "IIIMText.hh"
00002 
00003 #ifndef MAX
00004 #define MAX(x, y) ((x > y) ? (x) : (y))
00005 #endif
00006 
00007 void
00008 IIIMText::set_feedback_to_painter(
00009     QPainter *p,
00010     QWidget *pw,
00011     int val
00012 )
00013 {
00014     /* reset the QPainter */
00015     p->restore();
00016     p->save();
00017 
00018     if (val & IIIMP_FEEDBACK_0_REVERSE_VIDEO) {
00019        QColor f = p->pen().color();
00020        QColor b = p->backgroundColor();
00021        
00022        p->setPen(b);
00023        p->setBackgroundMode(Qt::OpaqueMode);
00024        p->setBackgroundColor(f);
00025     }
00026     if (val & IIIMP_FEEDBACK_0_UNDERLINE) {
00027        QFont f = p->font();
00028        f.setUnderline(true);
00029        p->setFont(f);
00030     }
00031     if (val & IIIMP_FEEDBACK_0_HIGHLIGHT) {
00032        QColorGroup::ColorRole cr = QColorGroup::HighlightedText;
00033 
00034        p->setBackgroundMode(Qt::OpaqueMode);
00035        if (pw)
00036            p->setBackgroundColor(pw->palette().active().color(cr));
00037     }
00038 }
00039 
00040 QSize
00041 IIIMText::text_element_size(
00042     QPainter *p,
00043     const QSize& size,
00044     const QString& str
00045 )
00046 {
00047     QRect r2;
00048     r2 = p->boundingRect(0, 0, 100000, 100000, Qt::AlignAuto, str);
00049     return QSize(size.width() + r2.width(), MAX(size.height(), r2.height()));
00050 }
00051 
00052 QSize
00053 IIIMText::output_string(
00054     QPainter *p,
00055     const QRect& r,
00056     const QSize& size,
00057     const QString& str
00058 )
00059 {
00060     QRect r2;
00061 
00062     r2 = p->boundingRect(r.left() + size.width(), r.top(),
00063                       r.left() + size.width() + 100000, r.bottom(),
00064                       Qt::AlignAuto, str);
00065     p->drawText(r2, Qt::AlignAuto, str);
00066     
00067     return QSize(size.width() + r2.width(), MAX(size.height(), r2.height()));
00068 }
00069 
00070 QSize
00071 IIIMText::draw(
00072     QPainter *p,
00073     QWidget *pw,
00074     const QRect& r
00075 )
00076 {
00077     IIIMF_status st;
00078     IIIMP_card16 ch;
00079     int i, j, n;
00080     int nfb;
00081     int cf0v, f0v;
00082     const IIIMP_card32 *pids, *pfbs;
00083     QString flagment;
00084     QSize totsize(0, 0);
00085 
00086     p->save();
00087 
00088     st = iiimcf_get_text_length(text, &n);
00089     if (st != IIIMF_STATUS_SUCCESS) return totsize;
00090     
00091     cf0v = 0;
00092     for (i = 0; i < n; i++) {
00093        if (iiimcf_get_char_with_feedback(text, i, &ch, &nfb, &pids, &pfbs)
00094            != IIIMF_STATUS_SUCCESS) return totsize;
00095        f0v = 0;
00096        for (j = 0; j < nfb; j++, pids++) {
00097            if (*pids == 0) {
00098               f0v = pfbs[j];
00099               break;
00100            }
00101        }
00102        // fprintf(stderr, "(%X, %d)", ch, f0v);
00103        if (f0v != cf0v) {
00104            if (!flagment.isEmpty()) {
00105               set_feedback_to_painter(p, pw, cf0v);
00106               totsize = output_string(p, r, totsize, flagment);
00107               flagment.setLength(0);
00108            }
00109            cf0v = f0v;
00110        }
00111        flagment.append(QChar(ch));
00112     }
00113     if (!flagment.isEmpty()) {
00114        set_feedback_to_painter(p, pw, cf0v);
00115        totsize = output_string(p, r, totsize, flagment);
00116     }
00117     // fprintf(stderr, "\n");
00118 
00119     p->restore();
00120 
00121     return totsize;
00122 }
00123 
00124 QSize
00125 IIIMText::get_size(
00126     QPainter *p,
00127     QWidget *pw
00128 )
00129 {
00130     IIIMF_status st;
00131     IIIMP_card16 ch;
00132     int i, j, n;
00133     int nfb;
00134     int cf0v, f0v;
00135     const IIIMP_card32 *pids, *pfbs;
00136     QString flagment;
00137     QSize totsize(0, 0);
00138 
00139     p->save();
00140 
00141     st = iiimcf_get_text_length(text, &n);
00142     if (st != IIIMF_STATUS_SUCCESS) return totsize;
00143     
00144     cf0v = 0;
00145     for (i = 0; i < n; i++) {
00146        if (iiimcf_get_char_with_feedback(text, i, &ch, &nfb, &pids, &pfbs)
00147            != IIIMF_STATUS_SUCCESS) return totsize;
00148        f0v = 0;
00149        for (j = 0; j < nfb; j++, pids++) {
00150            if (*pids == 0) {
00151               f0v = pfbs[j];
00152               break;
00153            }
00154        }
00155        // fprintf(stderr, "(%X, %d)", ch, f0v);
00156        if (f0v != cf0v) {
00157            if (!flagment.isEmpty()) {
00158               set_feedback_to_painter(p, pw, cf0v);
00159               totsize = text_element_size(p, totsize, flagment);
00160               flagment.setLength(0);
00161            }
00162            cf0v = f0v;
00163        }
00164        flagment.append(QChar(ch));
00165     }
00166     if (!flagment.isEmpty()) {
00167        set_feedback_to_painter(p, pw, cf0v);
00168        totsize = text_element_size(p, totsize, flagment);
00169     }
00170     // fprintf(stderr, "\n");
00171 
00172     p->restore();
00173 
00174     return totsize;
00175 }
00176 
00177 IIIMText::IIIMText(
00178     IIIMCF_text x_text
00179 )
00180 {
00181     iiimcf_duplicate_text(x_text, &text);
00182 }
00183 
00184 IIIMText::~IIIMText()
00185 {
00186     iiimcf_destroy_text(text);
00187 }
00188 
00189 /* Local Variables: */
00190 /* c-file-style: "iiim-project" */
00191 /* End: */