Subversion Repositories tpanel

Rev

Rev 437 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 437 Rev 439
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2020 to 2023 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2020 to 2024 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 3528... Line 3528...
3528
QFont MainWindow::loadFont(int number, const FONT_T& f, const FONT_STYLE style)
3528
QFont MainWindow::loadFont(int number, const FONT_T& f, const FONT_STYLE style)
3529
{
3529
{
3530
    DECL_TRACER("MainWindow::loadFont(int number, const FONT_t& f, const FONT_STYLE style)");
3530
    DECL_TRACER("MainWindow::loadFont(int number, const FONT_t& f, const FONT_STYLE style)");
3531
 
3531
 
3532
    QString path;
3532
    QString path;
3533
    string prjPath= TConfig::getProjectPath();
3533
    string prjPath = TConfig::getProjectPath();
3534
 
3534
 
3535
    if (number < 32)    // System font?
3535
    if (number < 32)    // System font?
3536
    {
3536
    {
3537
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
3537
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
3538
        path.append(prjPath).append("/__system/graphics/fonts/").append(f.file);
3538
        path.append(prjPath).append("/__system/graphics/fonts/").append(f.file);
Line 3573... Line 3573...
3573
        }
3573
        }
3574
    }
3574
    }
3575
 
3575
 
3576
    const QStringList ffamilies = QFontDatabase::families();
3576
    const QStringList ffamilies = QFontDatabase::families();
3577
    bool haveFont = false;
3577
    bool haveFont = false;
-
 
3578
    QString fname = QString::fromStdString(f.name);
3578
 
3579
 
3579
    for (const QString &family : ffamilies)
3580
    for (const QString &family : ffamilies)
3580
    {
3581
    {
3581
        if (family.compare(f.name.c_str()) == 0)
3582
        if (family == fname)
3582
        {
3583
        {
3583
            haveFont = true;
3584
            haveFont = true;
3584
            break;
3585
            break;
3585
        }
3586
        }
3586
    }
3587
    }
3587
 
3588
 
3588
    QFont font;
-
 
3589
    // Scale the font size
3589
    // Scale the font size
3590
    int pix = f.size;
3590
    int pix = f.size;
3591
 
3591
 
3592
    if (mScaleFactor > 0.0 && mScaleFactor != 1.0)
3592
    if (mScaleFactor > 0.0 && mScaleFactor != 1.0)
3593
        pix = static_cast<int>(static_cast<double>(f.size) / mScaleFactor);
3593
        pix = static_cast<int>(static_cast<double>(f.size) / mScaleFactor);
3594
 
3594
 
3595
    QString qstyle;
3595
    QString qstyle;
-
 
3596
    QFont font;
3596
 
3597
 
3597
    switch (style)
3598
    switch (style)
3598
    {
3599
    {
3599
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
3600
#if QT_VERSION >= QT_VERSION_CHECK(6, 6, 0)
3600
        case FONT_BOLD:         qstyle.assign("Bold"); break;
3601
        case FONT_BOLD:         qstyle.assign("Bold"); break;
Line 3602... Line 3603...
3602
        case FONT_BOLD_ITALIC:  qstyle.assign("Bold Italic"); break;
3603
        case FONT_BOLD_ITALIC:  qstyle.assign("Bold Italic"); break;
3603
 
3604
 
3604
        default:
3605
        default:
3605
            qstyle.assign("Normal");
3606
            qstyle.assign("Normal");
3606
#else
3607
#else
3607
    case FONT_BOLD:         qstyle = "Bold"; break;
3608
        case FONT_BOLD:         qstyle = "Bold"; break;
3608
    case FONT_ITALIC:       qstyle = "Italic"; break;
3609
        case FONT_ITALIC:       qstyle = "Italic"; break;
3609
    case FONT_BOLD_ITALIC:  qstyle = "Bold Italic"; break;
3610
        case FONT_BOLD_ITALIC:  qstyle = "Bold Italic"; break;
3610
 
3611
 
3611
    default:
3612
        default:
3612
        qstyle = "Normal";
3613
            qstyle = "Normal";
3613
#endif
3614
#endif
3614
    }
3615
    }
3615
 
3616
 
3616
    if (!haveFont)  // Did we found the font?
3617
    if (!haveFont)  // Did we found the font?
3617
    {               // No, then load it
3618
    {               // No, then load it
3618
        QFontDatabase::addApplicationFont(path);
3619
        QFontDatabase::addApplicationFont(path);
3619
        font = QFontDatabase::font(f.name.c_str(), qstyle, pix);
3620
        font = QFontDatabase::font(fname, qstyle, pix);
3620
        MSG_DEBUG("Font \"" << path.toStdString() << "\" was loaded");
3621
        MSG_DEBUG("Font \"" << path.toStdString() << "\" was loaded");
3621
    }
3622
    }
3622
    else
3623
    else
3623
    {
3624
    {
3624
        font.setFamily(f.name.c_str());
3625
        font.setFamily(fname);
3625
        font.setPointSize(pix);
3626
        font.setPointSize(pix);
3626
        font.setStyleName(qstyle);
3627
        font.setStyleName(qstyle);
3627
    }
3628
    }
3628
 
3629
 
3629
    string family = font.family().toStdString();
3630
    string family = font.family().toStdString();
Line 5388... Line 5389...
5388
            nobj.height = scale(height);
5389
            nobj.height = scale(height);
5389
            nobj.left = scale(button->getLeftPosition());
5390
            nobj.left = scale(button->getLeftPosition());
5390
            nobj.top = scale(button->getTopPosition());
5391
            nobj.top = scale(button->getTopPosition());
5391
        }
5392
        }
5392
 
5393
 
5393
        string text = button->getText(instance);
5394
        string text = button->getText(0);
-
 
5395
        string placeholder = button->getText(1);
5394
        string mask = button->getInputMask();
5396
        string mask = button->getInputMask();
5395
 
5397
 
5396
        if (button->isMultiLine())
5398
        if (button->isMultiLine())
5397
            text = ReplaceString(text, "|", "\n");
5399
            text = ReplaceString(text, "|", "\n");
5398
 
5400
 
Line 5402... Line 5404...
5402
        nobj.object.plaintext->move(nobj.left, nobj.top);
5404
        nobj.object.plaintext->move(nobj.left, nobj.top);
5403
        nobj.object.plaintext->setFixedSize(nobj.width, nobj.height);
5405
        nobj.object.plaintext->setFixedSize(nobj.width, nobj.height);
5404
        nobj.object.plaintext->setPadding(frame, frame, frame, frame);
5406
        nobj.object.plaintext->setPadding(frame, frame, frame, frame);
5405
        nobj.object.plaintext->setPasswordChar(button->getPasswordChar());
5407
        nobj.object.plaintext->setPasswordChar(button->getPasswordChar());
5406
        nobj.wid = nobj.object.plaintext->winId();
5408
        nobj.wid = nobj.object.plaintext->winId();
-
 
5409
 
-
 
5410
        if (!placeholder.empty())
-
 
5411
            nobj.object.plaintext->setPlaceholderText(placeholder);
-
 
5412
 
5407
        bool sys = false;
5413
        bool sys = false;
5408
 
5414
 
5409
        if (button->getAddressPort() == 0 || button->getChannelPort() == 0)
5415
        if (button->getAddressPort() == 0 || button->getChannelPort() == 0)
5410
        {
5416
        {
5411
            int ch = 0;
5417
            int ch = 0;
Line 5491... Line 5497...
5491
    }
5497
    }
5492
    else
5498
    else
5493
    {
5499
    {
5494
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
5500
        MSG_DEBUG("Object " << handleToString(handle) << " of type " << objectToString(obj->type) << " found!");
5495
 
5501
 
5496
        string text = button->getText(instance);
5502
        string text = button->getText(0);
-
 
5503
        string placeholder = button->getText(1);
5497
        string mask = button->getInputMask();
5504
        string mask = button->getInputMask();
-
 
5505
        MSG_DEBUG("Setting text: \"" << text << "\" with mask: \"" << mask << "\"");
-
 
5506
 
-
 
5507
        if (!placeholder.empty())
-
 
5508
            obj->object.plaintext->setPlaceholderText(placeholder);
5498
 
5509
 
5499
        if (button->isMultiLine())
5510
        if (button->isMultiLine())
5500
            text = ReplaceString(text, "|", "\n");
5511
            text = ReplaceString(text, "|", "\n");
5501
 
5512
 
5502
        obj->object.plaintext->setText(text);
5513
        obj->object.plaintext->setText(text);